Linux-SCSI Archive on lore.kernel.org
 help / color / Atom feed
From: Arnd Bergmann <arnd@arndb.de>
To: Linus Torvalds <torvalds@linux-foundation.org>
Cc: James Bottomley <James.Bottomley@hansenpartnership.com>,
	Al Viro <viro@zeniv.linux.org.uk>,
	Andrew Morton <akpm@linux-foundation.org>,
	linux-scsi <linux-scsi@vger.kernel.org>,
	linux-kernel <linux-kernel@vger.kernel.org>,
	Doug Gilbert <dgilbert@interlog.com>
Subject: Re: [PATCH] scsi: sg: fix v3 compat read/write interface
Date: Wed, 4 Dec 2019 21:35:23 +0100
Message-ID: <CAK8P3a35t7Of657kmhxF3m8MpJR8ZgiG01kNsXpXyuHmBtSorg@mail.gmail.com> (raw)
In-Reply-To: <CAHk-=wjBbi2xJZw+7Wqtt3W_mOUSPU2N4w-OES9WUUyXt-DnCg@mail.gmail.com>

On Wed, Dec 4, 2019 at 7:33 PM Linus Torvalds
<torvalds@linux-foundation.org> wrote:
>
> On Wed, Dec 4, 2019 at 6:08 AM Arnd Bergmann <arnd@arndb.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?

It almost works, but the part of the y2038 work that made all the
compat infrastructure visible on all architectures with or without
CONFIG_COMPAT never made it in after we decided to separate
the _time32 namespace from the compat_ namespace entirely.

It actually works on architectures that don't override asm/compat.h,
and on those that have CONFIG_COMPAT enabled, but for example
on arm64 with CONFIG_COMPAT=n I run into a build error because
asm-generic/compat.h is not included here, and getting that to
work reliably needed some rearranging of other files.

I could

a) dig out my old patches that did this right, so we can kill off
most of these #ifdefs in compat code throughout the kernel
(probably not this merge window),

b) change compat_sg_io_hdr to use plain types (u32, s32, ...), or

c) conditionally define another macro for SZ_COMPAT_SG_IO_HDR
like (pasted into gmail, won't apply)

diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c
index af152a7e71c7..039858014e18 100644
--- a/drivers/scsi/sg.c
+++ b/drivers/scsi/sg.c
@@ -198,6 +198,11 @@ static void sg_device_destroy(struct kref *kref);

 #define SZ_SG_HEADER sizeof(struct sg_header)
 #define SZ_SG_IO_HDR sizeof(sg_io_hdr_t)
+#ifdef CONFIG_COMPAT
+#define SZ_COMPAT_SG_IO_HDR SZ_SG_IO_HDR
+#else
+#define SZ_COMPAT_SG_IO_HDR sizeof(struct compat_sg_io_hdr)
+#endif
 #define SZ_SG_IOVEC sizeof(sg_iovec_t)
 #define SZ_SG_REQ_INFO sizeof(sg_req_info_t)

@@ -561,15 +566,12 @@ 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)) {
+               if (count < SZ_COMPAT_SG_IO_HDR) {
                        err = -EINVAL;
                        goto err_out;
                }
-       } else
-#endif
-       if (count < SZ_SG_IO_HDR) {
+       } else if (count < SZ_SG_IO_HDR) {
                err = -EINVAL;
                goto err_out;
        }

        Arnd

  reply index

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-11-30 18:10 [GIT PULL] first round of SCSI updates for the 5.4+ merge window James Bottomley
2019-12-02 21:57 ` Linus Torvalds
2019-12-02 22:40   ` James Bottomley
2019-12-04 14:05   ` Arnd Bergmann
2019-12-04 14:08     ` [PATCH] scsi: sg: fix v3 compat read/write interface Arnd Bergmann
2019-12-04 18:32       ` Linus Torvalds
2019-12-04 20:35         ` Arnd Bergmann [this message]
2019-12-02 22:00 ` [GIT PULL] first round of SCSI updates for the 5.4+ merge window pr-tracker-bot

Reply instructions:

You may reply publically 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=CAK8P3a35t7Of657kmhxF3m8MpJR8ZgiG01kNsXpXyuHmBtSorg@mail.gmail.com \
    --to=arnd@arndb.de \
    --cc=James.Bottomley@hansenpartnership.com \
    --cc=akpm@linux-foundation.org \
    --cc=dgilbert@interlog.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-scsi@vger.kernel.org \
    --cc=torvalds@linux-foundation.org \
    --cc=viro@zeniv.linux.org.uk \
    /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

Linux-SCSI Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-scsi/0 linux-scsi/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-scsi linux-scsi/ https://lore.kernel.org/linux-scsi \
		linux-scsi@vger.kernel.org
	public-inbox-index linux-scsi

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-scsi


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git