From: Greg KH <gregkh@linuxfoundation.org>
To: Jens Wiklander <jens.wiklander@linaro.org>
Cc: stable@vger.kernel.org, Sumit Garg <sumit.garg@linaro.org>,
Jerome Forissier <jerome.forissier@linaro.org>,
Nimish Mishra <neelam.nimish@gmail.com>,
Anirban Chakraborty <ch.anirban00727@gmail.com>,
Debdeep Mukhopadhyay <debdeep.mukhopadhyay@gmail.com>,
Linus Torvalds <torvalds@linux-foundation.org>,
Pavel Machek <pavel@denx.de>
Subject: Re: [PATCH] tee: add overflow check in tee_ioctl_shm_register()
Date: Tue, 23 Aug 2022 09:14:25 +0200 [thread overview]
Message-ID: <YwR+UTRq5stmn0jC@kroah.com> (raw)
In-Reply-To: <CAHUa44GdJQDmAtSyM5uYSoc4JX_EfrG9zSHCJgx4Jf+qU6LS_g@mail.gmail.com>
On Tue, Aug 23, 2022 at 09:00:43AM +0200, Jens Wiklander wrote:
> On Mon, Aug 22, 2022 at 4:57 PM Greg KH <gregkh@linuxfoundation.org> wrote:
> >
> > On Mon, Aug 22, 2022 at 04:29:05PM +0200, Jens Wiklander wrote:
> > > On Mon, Aug 22, 2022 at 3:32 PM Greg KH <gregkh@linuxfoundation.org> wrote:
> > > >
> > > > On Mon, Aug 22, 2022 at 03:12:27PM +0200, Jens Wiklander wrote:
> > > > > commit 573ae4f13f630d6660008f1974c0a8a29c30e18a upstream.
> > > > >
> > > > > With special lengths supplied by user space, tee_shm_register() has
> > > > > an integer overflow when calculating the number of pages covered by a
> > > > > supplied user space memory region.
> > > > >
> > > > > This may cause pin_user_pages_fast() to do a NULL pointer dereference.
> > > > >
> > > > > Fix this by adding an an explicit call to access_ok() in
> > > > > tee_ioctl_shm_register() to catch an invalid user space address early.
> > > > >
> > > > > Fixes: 033ddf12bcf5 ("tee: add register user memory")
> > > > > Cc: stable@vger.kernel.org # 5.4
> > > > > Cc: stable@vger.kernel.org # 5.10
> > > > > Reported-by: Nimish Mishra <neelam.nimish@gmail.com>
> > > > > Reported-by: Anirban Chakraborty <ch.anirban00727@gmail.com>
> > > > > Reported-by: Debdeep Mukhopadhyay <debdeep.mukhopadhyay@gmail.com>
> > > > > Suggested-by: Jerome Forissier <jerome.forissier@linaro.org>
> > > > > Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
> > > > > [JW: backport to stable 5.4 and 5.10 + update commit message]
> > > >
> > > > You already sent me a 5.4 version here:
> > > > https://lore.kernel.org/r/20220822092621.3691771-1-jens.wiklander@linaro.org
> > > >
> > > > And I applied that.
> > > >
> > > > And for 5.10, it's already in the tree as commit 578c349570d2 ("tee: add
> > > > overflow check in register_shm_helper()") and was in the 5.10.137
> > > > release.
> > > >
> > > > > Signed-off-by: Jens Wiklander <jens.wiklander@linaro.org>
> > > > > ---
> > > > > drivers/tee/tee_core.c | 3 +++
> > > > > 1 file changed, 3 insertions(+)
> > > > >
> > > > > diff --git a/drivers/tee/tee_core.c b/drivers/tee/tee_core.c
> > > > > index a7ccd4d2bd10..2db144d2d26f 100644
> > > > > --- a/drivers/tee/tee_core.c
> > > > > +++ b/drivers/tee/tee_core.c
> > > > > @@ -182,6 +182,9 @@ tee_ioctl_shm_register(struct tee_context *ctx,
> > > > > if (data.flags)
> > > > > return -EINVAL;
> > > > >
> > > > > + if (!access_ok((void __user *)(unsigned long)data.addr, data.length))
> > > > > + return -EFAULT;
> > > >
> > > > What I took in 5.10.137 was:
> > > >
> > > > + if (!access_ok((void __user *)addr, length))
> > > > + return ERR_PTR(-EFAULT);
> > > >
> > > > Should I fix it up to look like what you sent here instead?
> > >
> > > Yes, please.
> >
> > Ok, no, that does not work on 5.10.y at all, it blows up with the
> > obvious issue that there is no data pointer in this function. It's also
> > in a different file, drivers/tee/tee_shm.c
> >
> > So I'm going to leave 5.10.y alone for now, I think it's fixed.
>
> It works somewhat, but there's the potential memory leak that Pavel
> Machek pointed out,
> https://lore.kernel.org/lkml/20220822111546.GA7795@duo.ucw.cz/ .
>
> The 5.4 patch has a better approach since it verifies the supplied
> address range early before we do anything that must be undone on
> error.
> The 5.4 patch changes tee_ioctl_shm_register() instead, which is the
> function one step up in the call chain. This approach should be taken
> for all kernels before 53e16519c2ec ("tee: replace
> tee_shm_register()"), that is, before v5.18 if I'm reading the git log
> correctly.
>
> access_ok() went from taking three arguments to two sometime after
> v4.19, why that patch is slightly different.
Ok, can you send me a new fix-up patch, on top of the latest 5.10.y
release, to resolve the 5.10 issue?
thanks,
greg k-h
next prev parent reply other threads:[~2022-08-23 7:14 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-08-22 13:12 [PATCH] tee: add overflow check in tee_ioctl_shm_register() Jens Wiklander
2022-08-22 13:32 ` Greg KH
2022-08-22 14:29 ` Jens Wiklander
2022-08-22 14:57 ` Greg KH
2022-08-23 7:00 ` Jens Wiklander
2022-08-23 7:14 ` Greg KH [this message]
2022-11-08 6:12 ` Sumit Garg
2022-11-08 6:23 ` Greg Kroah-Hartman
-- strict thread matches above, loose matches on Subject: below --
2022-08-22 15:02 Jens Wiklander
2022-08-22 15:13 ` Greg KH
2022-08-22 9:26 Jens Wiklander
2022-08-22 9:59 ` Greg KH
2022-08-22 10:01 ` Greg KH
2022-08-22 12:07 ` Jens Wiklander
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=YwR+UTRq5stmn0jC@kroah.com \
--to=gregkh@linuxfoundation.org \
--cc=ch.anirban00727@gmail.com \
--cc=debdeep.mukhopadhyay@gmail.com \
--cc=jens.wiklander@linaro.org \
--cc=jerome.forissier@linaro.org \
--cc=neelam.nimish@gmail.com \
--cc=pavel@denx.de \
--cc=stable@vger.kernel.org \
--cc=sumit.garg@linaro.org \
--cc=torvalds@linux-foundation.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox