All of lore.kernel.org
 help / color / mirror / Atom feed
From: Dan Carpenter <dan.carpenter@oracle.com>
To: Denis Efremov <denis.e.efremov@oracle.com>
Cc: Dmitry Torokhov <dmitry.torokhov@gmail.com>,
	Stephen Kitt <steve@sk2.org>,
	linux-input@vger.kernel.org, kernel-janitors@vger.kernel.org,
	Alexander Larkin <avlarkin82@gmail.com>
Subject: Re: [PATCH] Input: joydev - prevent potential read overflow in ioctl
Date: Sat, 3 Jul 2021 15:43:51 +0300	[thread overview]
Message-ID: <20210703124351.GA26651@kadam> (raw)
In-Reply-To: <1c351258-65e8-8984-8ffa-64eb316e1573@oracle.com>

On Sat, Jul 03, 2021 at 02:20:13PM +0300, Denis Efremov wrote:
> Hi,
> 
> CVE-2021-3612 was assigned to this patch.
> 
> 
> On 2/17/21 9:10 AM, Dan Carpenter wrote:
> > The problem here is that "len" might be less than "joydev->nabs" so the
> > loops which verfy abspam[i] and keypam[] might read beyond the buffer.
> 
> 
> The added check looks insufficient to me. There are second loops in these
> functions with unpatched "i < joydev->nabs;" and "i < joydev->nkey;" checks.
> 

Thanks, Denis.

You're right.  The fix isn't complete.  We discussed this in a different
thread but I sort of assumed it was dealt with and didn't follow up.  :/

https://lore.kernel.org/lkml/20210620120030.1513655-1-avlarkin82@gmail.com/

regards,
dan carpenter

> > 
> > Fixes: 999b874f4aa3 ("Input: joydev - validate axis/button maps before clobbering current ones")
> > Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
> > ---
> >  drivers/input/joydev.c | 4 ++--
> >  1 file changed, 2 insertions(+), 2 deletions(-)
> > 
> > diff --git a/drivers/input/joydev.c b/drivers/input/joydev.c
> > index a2b5fbba2d3b..750f4513fe20 100644
> > --- a/drivers/input/joydev.c
> > +++ b/drivers/input/joydev.c
> > @@ -456,7 +456,7 @@ static int joydev_handle_JSIOCSAXMAP(struct joydev *joydev,
> >  	if (IS_ERR(abspam))
> >  		return PTR_ERR(abspam);
> >  
> > -	for (i = 0; i < joydev->nabs; i++) {
> > +	for (i = 0; i < len && i < joydev->nabs; i++) {
> >  		if (abspam[i] > ABS_MAX) {
> >  			retval = -EINVAL;
> >  			goto out;
> 
>         memcpy(joydev->abspam, abspam, len);
> 
>         for (i = 0; i < joydev->nabs; i++) // <== HERE
>                 joydev->absmap[joydev->abspam[i]] = i;
> 
> 
> > @@ -487,7 +487,7 @@ static int joydev_handle_JSIOCSBTNMAP(struct joydev *joydev,
> >  	if (IS_ERR(keypam))
> >  		return PTR_ERR(keypam);
> >  
> > -	for (i = 0; i < joydev->nkey; i++) {
> > +	for (i = 0; i < (len / 2) && i < joydev->nkey; i++) {
> >  		if (keypam[i] > KEY_MAX || keypam[i] < BTN_MISC) {
> >  			retval = -EINVAL;
> >  			goto out;
> > 
> 
>         memcpy(joydev->keypam, keypam, len);
> 
>         for (i = 0; i < joydev->nkey; i++) // <== HERE
>                 joydev->keymap[keypam[i] - BTN_MISC] = i;
> 
> 
> Also at the beginning of joydev_handle_JSIOCSAXMAP() there is a
> 	len = min(len, sizeof(joydev->abspam));
> 	abspam = memdup_user(argp, len);
> 
> Maybe we can call min(len, joydev->nabs) instead or even min3() and
> use only len in the for loops then? Same for joydev_handle_JSIOCSBTNMAP.
> 
> Thanks,
> Denis

  reply	other threads:[~2021-07-03 12:44 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-02-17  6:10 [PATCH] Input: joydev - prevent potential read overflow in ioctl Dan Carpenter
2021-02-19  3:17 ` Dmitry Torokhov
2021-02-19  8:32   ` Dan Carpenter
2021-02-19 18:54     ` Dmitry Torokhov
2021-07-03 11:20 ` Denis Efremov
2021-07-03 12:43   ` Dan Carpenter [this message]
2021-07-03 14:34     ` Denis Efremov

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=20210703124351.GA26651@kadam \
    --to=dan.carpenter@oracle.com \
    --cc=avlarkin82@gmail.com \
    --cc=denis.e.efremov@oracle.com \
    --cc=dmitry.torokhov@gmail.com \
    --cc=kernel-janitors@vger.kernel.org \
    --cc=linux-input@vger.kernel.org \
    --cc=steve@sk2.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.