linux-kernel-mentees.lists.linuxfoundation.org archive mirror
 help / color / mirror / Atom feed
From: Arnd Bergmann <arnd@arndb.de>
To: Peilin Ye <yepeilin.cs@gmail.com>
Cc: linux-kernel-mentees@lists.linuxfoundation.org,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	Dan Carpenter <dan.carpenter@oracle.com>
Subject: Re: [Linux-kernel-mentees] [PATCH v3] media/v4l2-core: Fix kernel-infoleak in video_put_user()
Date: Tue, 28 Jul 2020 11:10:20 +0200	[thread overview]
Message-ID: <CAK8P3a1QZxPfLF3-jYzPGmHR_TOUfET+92x_L_K4Tkqf+v9bDA@mail.gmail.com> (raw)
In-Reply-To: <20200727223357.GA329006@PWN>

On Tue, Jul 28, 2020 at 12:34 AM Peilin Ye <yepeilin.cs@gmail.com> wrote:
>
> On Mon, Jul 27, 2020 at 04:16:08PM +0300, Dan Carpenter wrote:
> > drivers/block/floppy.c:3132 raw_cmd_copyout() warn: check that 'cmd' doesn't leak information (struct has a hole after 'flags')
>
> (Removed some Cc: recipients from the list.)
>
> I'm not very sure, but I think this one is also a false positive.
>
> Here Smatch is complaining about a linked list called `my_raw_cmd`
> defined in raw_cmd_ioctl():
>
> drivers/block/floppy.c:3249:
>
>         ret = raw_cmd_copyin(cmd, param, &my_raw_cmd);
>
> In raw_cmd_copyin(), each element of the linked list is allocated by
> kmalloc() then copied from user:
>
> drivers/block/floppy.c:3180:
>
> loop:
>         ptr = kmalloc(sizeof(struct floppy_raw_cmd), GFP_KERNEL);
>               ^^^^^^^
>         if (!ptr)
>                 return -ENOMEM;
>         *rcmd = ptr;
>         ret = copy_from_user(ptr, param, sizeof(*ptr));
>               ^^^^^^^^^^^^^^
>
> I think copy_from_user() is filling in the paddings inside `struct
> floppy_raw_cmd`?

I am not completely sure about this one either. copy_from_user()
would indeed fill the pad bytes in the structure, but there is another
problem:

                struct floppy_raw_cmd cmd = *ptr;
                cmd.next = NULL;
                cmd.kernel_data = NULL;
                ret = copy_to_user(param, &cmd, sizeof(cmd));

IIRC the struct assignment is allowed to be done per member
and skip the padding, so the on-stack copy can then again
contain a data leak. The compiler is likely to turn a struct
assignment into a memcpy(), but as the code then goes on
to set two members individually, I suppose doing a per-member
copy would not be unreasonable behavior either and doing
a memcpy() instead of an assignment would be the safe
choice.

If someone has a clearer understanding of what the compiler
is actually allowed to do here, please let us know.

       Arnd
_______________________________________________
Linux-kernel-mentees mailing list
Linux-kernel-mentees@lists.linuxfoundation.org
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees

  reply	other threads:[~2020-07-28  9:10 UTC|newest]

Thread overview: 38+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-07-26 16:44 [Linux-kernel-mentees] [PATCH] media/v4l2-core: Fix kernel-infoleak in video_put_user() Peilin Ye
2020-07-26 17:30 ` Laurent Pinchart
2020-07-26 18:07   ` Peilin Ye
2020-07-26 22:08     ` Laurent Pinchart
2020-07-26 22:15       ` Peilin Ye
2020-07-26 18:12   ` Peilin Ye
2020-07-26 22:05 ` [Linux-kernel-mentees] [PATCH v2] " Peilin Ye
2020-07-26 22:10   ` Laurent Pinchart
2020-07-26 22:16     ` Peilin Ye
2020-07-26 22:27   ` [Linux-kernel-mentees] [PATCH v3] " Peilin Ye
2020-07-27  7:25     ` Arnd Bergmann
2020-07-27  7:56       ` Peilin Ye
2020-07-27 13:16       ` Dan Carpenter
2020-07-27 14:05         ` Arnd Bergmann
2020-07-27 14:14           ` Peilin Ye
2020-07-27 14:20             ` Arnd Bergmann
2020-07-27 14:46             ` Dan Carpenter
2020-07-27 15:30               ` Peilin Ye
2020-07-27 14:43           ` Dan Carpenter
2020-07-27 14:55             ` Arnd Bergmann
2020-07-27 22:04         ` Peilin Ye
2020-07-28  9:00           ` Arnd Bergmann
2020-07-28 10:02           ` Dan Carpenter
2020-07-27 22:33         ` Peilin Ye
2020-07-28  9:10           ` Arnd Bergmann [this message]
2020-07-28  9:47           ` Dan Carpenter
2020-07-28 13:13             ` Peilin Ye
2020-07-28 12:22         ` Linus Walleij
2020-07-28 13:06           ` Dan Carpenter
2020-07-28 13:58             ` Arnd Bergmann
2020-07-30  8:07               ` Bartosz Golaszewski
2020-07-30  8:15                 ` Arnd Bergmann
2020-07-30  8:38                   ` Andy Shevchenko
2020-07-30  9:18                     ` Arnd Bergmann
2020-07-30 11:48                       ` Andy Shevchenko
2020-07-30 13:49                         ` Arnd Bergmann
2020-08-02 16:55         ` Peilin Ye
2020-07-27  8:00     ` [Linux-kernel-mentees] [PATCH v4] " Peilin Ye

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=CAK8P3a1QZxPfLF3-jYzPGmHR_TOUfET+92x_L_K4Tkqf+v9bDA@mail.gmail.com \
    --to=arnd@arndb.de \
    --cc=dan.carpenter@oracle.com \
    --cc=linux-kernel-mentees@lists.linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=yepeilin.cs@gmail.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;
as well as URLs for NNTP newsgroup(s).