linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
To: Arnd Bergmann <arnd@kernel.org>
Cc: Mauro Carvalho Chehab <mchehab@kernel.org>,
	Dmitry Vyukov <dvyukov@google.com>, Arnd Bergmann <arnd@arndb.de>,
	syzbot+142888ffec98ab194028@syzkaller.appspotmail.com,
	Hans Verkuil <hverkuil-cisco@xs4all.nl>,
	Sakari Ailus <sakari.ailus@linux.intel.com>,
	linux-media@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH 2/2] media: v4l2-core: explicitly clear ioctl input data
Date: Thu, 18 Mar 2021 17:07:45 +0200	[thread overview]
Message-ID: <YFNswT3+488rC5Tl@pendragon.ideasonboard.com> (raw)
In-Reply-To: <20210318134334.2933141-2-arnd@kernel.org>

Hi Arnd,

Thank you for the patch.

On Thu, Mar 18, 2021 at 02:43:19PM +0100, Arnd Bergmann wrote:
> From: Arnd Bergmann <arnd@arndb.de>
> 
> As seen from a recent syzbot bug report, mistakes in the compat ioctl
> implementation can lead to uninitialized kernel stack data getting used
> as input for driver ioctl handlers.
> 
> The reported bug is now fixed, but it's possible that other related
> bugs are still present or get added in the future. As the drivers need
> to check user input already, the possible impact is fairly low, but it
> might still cause an information leak.
> 
> To be on the safe side, always clear the entire ioctl buffer before
> calling the conversion handler functions that are meant to initialize
> them.
> 
> Signed-off-by: Arnd Bergmann <arnd@arndb.de>

Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>

> ---
>  drivers/media/v4l2-core/v4l2-ioctl.c | 51 ++++++++++++++++------------
>  1 file changed, 29 insertions(+), 22 deletions(-)
> 
> diff --git a/drivers/media/v4l2-core/v4l2-ioctl.c b/drivers/media/v4l2-core/v4l2-ioctl.c
> index 2b1bb68dc27f..6cec92d0972c 100644
> --- a/drivers/media/v4l2-core/v4l2-ioctl.c
> +++ b/drivers/media/v4l2-core/v4l2-ioctl.c
> @@ -3164,12 +3164,23 @@ static int video_get_user(void __user *arg, void *parg,
>  
>  	if (cmd == real_cmd) {
>  		if (copy_from_user(parg, (void __user *)arg, n))
> -			err = -EFAULT;
> -	} else if (in_compat_syscall()) {
> -		err = v4l2_compat_get_user(arg, parg, cmd);
> -	} else {
> -		switch (cmd) {
> +			return -EFAULT;
> +
> +		/* zero out anything we don't copy from userspace */
> +		if (n < _IOC_SIZE(real_cmd))
> +			memset((u8 *)parg + n, 0, _IOC_SIZE(real_cmd) - n);
> +
> +		return 0;
> +	}
> +
> +	/* zero out whole buffer first to deal with missing emulation */
> +	memset(parg, 0, _IOC_SIZE(real_cmd));
> +
> +	if (in_compat_syscall())
> +		return v4l2_compat_get_user(arg, parg, cmd);
> +
>  #if !defined(CONFIG_64BIT) && defined(CONFIG_COMPAT_32BIT_TIME)
> +	switch (cmd) {
>  		case VIDIOC_QUERYBUF_TIME32:
>  		case VIDIOC_QBUF_TIME32:
>  		case VIDIOC_DQBUF_TIME32:
> @@ -3182,28 +3193,24 @@ static int video_get_user(void __user *arg, void *parg,
>  
>  			*vb = (struct v4l2_buffer) {
>  				.index		= vb32.index,
> -					.type		= vb32.type,
> -					.bytesused	= vb32.bytesused,
> -					.flags		= vb32.flags,
> -					.field		= vb32.field,
> -					.timestamp.tv_sec	= vb32.timestamp.tv_sec,
> -					.timestamp.tv_usec	= vb32.timestamp.tv_usec,
> -					.timecode	= vb32.timecode,
> -					.sequence	= vb32.sequence,
> -					.memory		= vb32.memory,
> -					.m.userptr	= vb32.m.userptr,
> -					.length		= vb32.length,
> -					.request_fd	= vb32.request_fd,
> +				.type		= vb32.type,
> +				.bytesused	= vb32.bytesused,
> +				.flags		= vb32.flags,
> +				.field		= vb32.field,
> +				.timestamp.tv_sec	= vb32.timestamp.tv_sec,
> +				.timestamp.tv_usec	= vb32.timestamp.tv_usec,
> +				.timecode	= vb32.timecode,
> +				.sequence	= vb32.sequence,
> +				.memory		= vb32.memory,
> +				.m.userptr	= vb32.m.userptr,
> +				.length		= vb32.length,
> +				.request_fd	= vb32.request_fd,
>  			};
>  			break;
>  		}
> -#endif
> -		}
>  	}
> +#endif
>  
> -	/* zero out anything we don't copy from userspace */
> -	if (!err && n < _IOC_SIZE(real_cmd))
> -		memset((u8 *)parg + n, 0, _IOC_SIZE(real_cmd) - n);
>  	return err;
>  }
>  

-- 
Regards,

Laurent Pinchart

  reply	other threads:[~2021-03-18 15:09 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-18 13:43 [PATCH 1/2] media: v4l2-core: ignore native time32 ioctls on 64-bit Arnd Bergmann
2021-03-18 13:43 ` [PATCH 2/2] media: v4l2-core: explicitly clear ioctl input data Arnd Bergmann
2021-03-18 15:07   ` Laurent Pinchart [this message]
2021-03-18 15:00 ` [PATCH 1/2] media: v4l2-core: ignore native time32 ioctls on 64-bit Laurent Pinchart
2021-03-18 15:24   ` Arnd Bergmann
2021-03-21  8:50 ` Hans Verkuil
2021-03-25  7:41   ` Hans Verkuil

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=YFNswT3+488rC5Tl@pendragon.ideasonboard.com \
    --to=laurent.pinchart@ideasonboard.com \
    --cc=arnd@arndb.de \
    --cc=arnd@kernel.org \
    --cc=dvyukov@google.com \
    --cc=hverkuil-cisco@xs4all.nl \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-media@vger.kernel.org \
    --cc=mchehab@kernel.org \
    --cc=sakari.ailus@linux.intel.com \
    --cc=syzbot+142888ffec98ab194028@syzkaller.appspotmail.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).