From: Christoph Hellwig <hch@infradead.org>
To: Arnd Bergmann <arnd@arndb.de>
Cc: Kashyap Desai <kashyap.desai@broadcom.com>,
Sumit Saxena <sumit.saxena@broadcom.com>,
Shivasharan S <shivasharan.srikanteshwara@broadcom.com>,
"James E . J . Bottomley" <jejb@linux.ibm.com>,
"Martin K . Petersen" <martin.petersen@oracle.com>,
Christoph Hellwig <hch@infradead.org>,
anand.lodnoor@broadcom.com, megaraidlinux.pdl@broadcom.com,
linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2 3/3] scsi: megaraid_sas: simplify compat_ioctl handling
Date: Sat, 19 Sep 2020 06:26:22 +0100 [thread overview]
Message-ID: <20200919052622.GE30063@infradead.org> (raw)
In-Reply-To: <20200918121543.1466090-1-arnd@arndb.de>
On Fri, Sep 18, 2020 at 02:15:43PM +0200, Arnd Bergmann wrote:
> There have been several attempts to fix serious problems
> in the compat handling in megasas_mgmt_compat_ioctl_fw(),
> and it also uses the compat_alloc_user_space() function.
>
> Folding the compat handling into the regular ioctl
> function with in_compat_syscall() simplifies it a lot and
> avoids some of the remaining problems:
>
> - missing handling of unaligned pointers
> - overflowing the ioc->frame.raw array from
> invalid input
> - compat_alloc_user_space()
>
> Signed-off-by: Arnd Bergmann <arnd@arndb.de>
> ---
> v2: address review comments from hch
> ---
> drivers/scsi/megaraid/megaraid_sas.h | 2 -
> drivers/scsi/megaraid/megaraid_sas_base.c | 117 +++++++++-------------
> include/linux/compat.h | 10 +-
> 3 files changed, 50 insertions(+), 79 deletions(-)
>
> diff --git a/drivers/scsi/megaraid/megaraid_sas.h b/drivers/scsi/megaraid/megaraid_sas.h
> index 5e4137f10e0e..0f808d63580e 100644
> --- a/drivers/scsi/megaraid/megaraid_sas.h
> +++ b/drivers/scsi/megaraid/megaraid_sas.h
> @@ -2605,7 +2605,6 @@ struct megasas_aen {
> u32 class_locale_word;
> } __attribute__ ((packed));
>
> -#ifdef CONFIG_COMPAT
> struct compat_megasas_iocpacket {
> u16 host_no;
> u16 __pad1;
> @@ -2621,7 +2620,6 @@ struct compat_megasas_iocpacket {
> } __attribute__ ((packed));
>
> #define MEGASAS_IOC_FIRMWARE32 _IOWR('M', 1, struct compat_megasas_iocpacket)
> -#endif
>
> #define MEGASAS_IOC_FIRMWARE _IOWR('M', 1, struct megasas_iocpacket)
> #define MEGASAS_IOC_GET_AEN _IOW('M', 3, struct megasas_aen)
> diff --git a/drivers/scsi/megaraid/megaraid_sas_base.c b/drivers/scsi/megaraid/megaraid_sas_base.c
> index c3de69f3bee8..d91951ee16ab 100644
> --- a/drivers/scsi/megaraid/megaraid_sas_base.c
> +++ b/drivers/scsi/megaraid/megaraid_sas_base.c
> @@ -8279,16 +8279,18 @@ megasas_mgmt_fw_ioctl(struct megasas_instance *instance,
> * copy out the sense
> */
> if (ioc->sense_len) {
> + void __user *uptr;
> /*
> * sense_ptr points to the location that has the user
> * sense buffer address
> */
> + sense_ptr = (void *)ioc->frame.raw + ioc->sense_off;
> + if (in_compat_syscall())
> + uptr = compat_ptr(get_unaligned((u32 *)sense_ptr));
should the u32 * here by a compat_uptr *? Not tat it would make a
difference, just better document what we are doing.
> + for (i = 0; i < MAX_IOCTL_SGE; i++) {
> + compat_uptr_t iov_base;
> + if (get_user(iov_base, &cioc->sgl[i].iov_base) ||
> + get_user(ioc->sgl[i].iov_len, &cioc->sgl[i].iov_len)) {
> + goto out;
> + }
I don't think we need the braces here.
> + return ioc;
> +out:
> + kfree(ioc);
> +
> + return ERR_PTR(err);
spurious empty line.
> --- a/include/linux/compat.h
> +++ b/include/linux/compat.h
> @@ -91,6 +91,11 @@
> static inline long __do_compat_sys##name(__MAP(x,__SC_DECL,__VA_ARGS__))
> #endif /* COMPAT_SYSCALL_DEFINEx */
>
> +struct compat_iovec {
> + compat_uptr_t iov_base;
> + compat_size_t iov_len;
> +};
> +
> #ifdef CONFIG_COMPAT
>
> #ifndef compat_user_stack_pointer
> @@ -248,11 +253,6 @@ typedef struct compat_siginfo {
> } _sifields;
> } compat_siginfo_t;
>
> -struct compat_iovec {
> - compat_uptr_t iov_base;
> - compat_size_t iov_len;
> -};
This should probably go into a separate patch instead of being hidden
in a driver patch.
But except for these nitpicks the change looks good:
Reviewed-by: Christoph Hellwig <hch@lst.de>
next prev parent reply other threads:[~2020-09-19 5:26 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-09-18 12:09 [PATCH v2 1/3] scsi: aacraid: improve compat_ioctl handlers Arnd Bergmann
2020-09-18 12:15 ` [PATCH v2 2/3] scsi: megaraid_sas: check user-provided offsets Arnd Bergmann
2020-09-19 5:23 ` Christoph Hellwig
2020-09-18 12:15 ` [PATCH v2 3/3] scsi: megaraid_sas: simplify compat_ioctl handling Arnd Bergmann
2020-09-19 5:26 ` Christoph Hellwig [this message]
2020-09-26 21:19 ` Arnd Bergmann
2020-09-27 4:52 ` Joe Perches
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200919052622.GE30063@infradead.org \
--to=hch@infradead.org \
--cc=anand.lodnoor@broadcom.com \
--cc=arnd@arndb.de \
--cc=jejb@linux.ibm.com \
--cc=kashyap.desai@broadcom.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-scsi@vger.kernel.org \
--cc=martin.petersen@oracle.com \
--cc=megaraidlinux.pdl@broadcom.com \
--cc=shivasharan.srikanteshwara@broadcom.com \
--cc=sumit.saxena@broadcom.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®