[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAHk-=wjBbi2xJZw+7Wqtt3W_mOUSPU2N4w-OES9WUUyXt-DnCg@mail.gmail.com>
Date: Wed, 4 Dec 2019 10:32:56 -0800
From: Linus Torvalds <torvalds@...ux-foundation.org>
To: Arnd Bergmann <arnd@...db.de>
Cc: James Bottomley <James.Bottomley@...senpartnership.com>,
Al Viro <viro@...iv.linux.org.uk>,
Andrew Morton <akpm@...ux-foundation.org>,
linux-scsi <linux-scsi@...r.kernel.org>,
linux-kernel <linux-kernel@...r.kernel.org>,
Doug Gilbert <dgilbert@...erlog.com>
Subject: Re: [PATCH] scsi: sg: fix v3 compat read/write interface
On Wed, Dec 4, 2019 at 6:08 AM Arnd Bergmann <arnd@...db.de> wrote:
>
> To address both of these, move the definition of compat_sg_io_hdr
> into a scsi/sg.h to make it visible to sg.c and rewrite the logic
> for reading req_pack_id as well as the size check to a simpler
> version that gets the expected results.
I think the patch is a good thing, except for this part:
> @@ -575,6 +561,14 @@ sg_new_read(Sg_fd * sfp, char __user *buf, size_t count, Sg_request * srp)
> int err = 0, err2;
> int len;
>
> +#ifdef CONFIG_COMPAT
> + if (in_compat_syscall()) {
> + if (count < sizeof(struct compat_sg_io_hdr)) {
> + err = -EINVAL;
> + goto err_out;
> + }
> + } else
> +#endif
> if (count < SZ_SG_IO_HDR) {
> err = -EINVAL;
> goto err_out;
Yes, yes, I know we do things like that in some other places too, but
I really detest this kind of ifdeffery.
That
} else
#endif
if (count < SZ_SG_IO_HDR) {
is just evil. Please don't add things like this where the #ifdef
section has subtle semantic continuations outside of it. If somebody
adds a statement in between there, it now acts completely wrong.
I think you can remove the #ifdef entirely. If CONFIG_COMPAT isn't
set, I think in_compat_syscall() just turns to 0, and the code gets
optimized away.
Hmm?
Linus
Powered by blists - more mailing lists