All of lore.kernel.org
 help / color / mirror / Atom feed
From: Dan Carpenter <dan.carpenter@oracle.com>
To: Phil Elwell <phil@raspberrypi.com>
Cc: devel@driverdev.osuosl.org, Arnd Bergmann <arnd@arndb.de>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	bcm-kernel-feedback-list@broadcom.com,
	linux-arm-kernel@lists.infradead.org,
	Nicolas Saenz Julienne <nsaenzjulienne@suse.de>,
	linux-rpi-kernel@lists.infradead.org
Subject: Re: [PATCH 1/2] staging: vchiq: Fix bulk userdata handling
Date: Tue, 5 Jan 2021 14:01:41 +0300	[thread overview]
Message-ID: <20210105110140.GW2809@kadam> (raw)
In-Reply-To: <989ef44f-2afe-5147-1277-74df56797a4c@raspberrypi.com>

On Mon, Jan 04, 2021 at 07:26:42PM +0000, Phil Elwell wrote:
> On 04/01/2021 18:31, Dan Carpenter wrote:
> > On Mon, Jan 04, 2021 at 12:09:27PM +0000, Phil Elwell wrote:
> > > The addition of the local 'userdata' pointer to
> > > vchiq_irq_queue_bulk_tx_rx omitted the case where neither BLOCKING nor
> > > WAITING modes are used, in which case the value provided by the
> > > caller is replaced with a NULL.
> > > 
> > > Fixes: 4184da4f316a ("staging: vchiq: fix __user annotations")
> > > 
> > > Signed-off-by: Phil Elwell <phil@raspberrypi.com>
> > > ---
> > >   drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c | 4 +++-
> > >   1 file changed, 3 insertions(+), 1 deletion(-)
> > > 
> > > diff --git a/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c b/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c
> > > index f500a7043805..2a8883673ba1 100644
> > > --- a/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c
> > > +++ b/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c
> > > @@ -958,7 +958,7 @@ static int vchiq_irq_queue_bulk_tx_rx(struct vchiq_instance *instance,
> > >   	struct vchiq_service *service;
> > >   	struct bulk_waiter_node *waiter = NULL;
> > >   	bool found = false;
> > > -	void *userdata = NULL;
> > > +	void *userdata;
> > >   	int status = 0;
> > >   	int ret;
> > > @@ -997,6 +997,8 @@ static int vchiq_irq_queue_bulk_tx_rx(struct vchiq_instance *instance,
> > >   			"found bulk_waiter %pK for pid %d", waiter,
> > >   			current->pid);
> > >   		userdata = &waiter->bulk_waiter;
> > > +	} else {
> > > +		userdata = args->userdata;
> > 
> > "args->userdata" is marked as a user pointer so we really don't want to
> > mix user and kernel pointers here.  Presumably this opens up a large
> > security hole.
> 
> It's an opaque, pointer-sized token that only exists to bereturned to userspace (or not,
> without this patch) - it's hard to see that as a security hole.

I was assuming the bug here was a NULL dereference...  Apparently that's
not the case?  The commit message needs to be updated to be more clear
about how the bug looks like to the user.

Are we using the "&waiter->bulk_waiter" as a "token to be returned to
userspace" as well?  It looks like maybe it is in vchiq_put_completion().
That defeats KASLR and is a different sort of security problem.

Mixing __user pointers and regular pointers is dangerous and has lead to
security problems in this driver in the past.  But also mixing mixing
tokens with pointers just makes the code hard to read.  Instead of
undoing Arnd's work where he split the user space and kernel pointers
apart we should go ahead and spit it up even more.  At least add a giant
FIXME comment and an item in the TODO list so we don't forget to do this
before removing the code from staging.

regards,
dan carpenter
_______________________________________________
devel mailing list
devel@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel

WARNING: multiple messages have this Message-ID (diff)
From: Dan Carpenter <dan.carpenter@oracle.com>
To: Phil Elwell <phil@raspberrypi.com>
Cc: devel@driverdev.osuosl.org, Arnd Bergmann <arnd@arndb.de>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	bcm-kernel-feedback-list@broadcom.com,
	linux-arm-kernel@lists.infradead.org,
	Nicolas Saenz Julienne <nsaenzjulienne@suse.de>,
	linux-rpi-kernel@lists.infradead.org
Subject: Re: [PATCH 1/2] staging: vchiq: Fix bulk userdata handling
Date: Tue, 5 Jan 2021 14:01:41 +0300	[thread overview]
Message-ID: <20210105110140.GW2809@kadam> (raw)
In-Reply-To: <989ef44f-2afe-5147-1277-74df56797a4c@raspberrypi.com>

On Mon, Jan 04, 2021 at 07:26:42PM +0000, Phil Elwell wrote:
> On 04/01/2021 18:31, Dan Carpenter wrote:
> > On Mon, Jan 04, 2021 at 12:09:27PM +0000, Phil Elwell wrote:
> > > The addition of the local 'userdata' pointer to
> > > vchiq_irq_queue_bulk_tx_rx omitted the case where neither BLOCKING nor
> > > WAITING modes are used, in which case the value provided by the
> > > caller is replaced with a NULL.
> > > 
> > > Fixes: 4184da4f316a ("staging: vchiq: fix __user annotations")
> > > 
> > > Signed-off-by: Phil Elwell <phil@raspberrypi.com>
> > > ---
> > >   drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c | 4 +++-
> > >   1 file changed, 3 insertions(+), 1 deletion(-)
> > > 
> > > diff --git a/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c b/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c
> > > index f500a7043805..2a8883673ba1 100644
> > > --- a/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c
> > > +++ b/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c
> > > @@ -958,7 +958,7 @@ static int vchiq_irq_queue_bulk_tx_rx(struct vchiq_instance *instance,
> > >   	struct vchiq_service *service;
> > >   	struct bulk_waiter_node *waiter = NULL;
> > >   	bool found = false;
> > > -	void *userdata = NULL;
> > > +	void *userdata;
> > >   	int status = 0;
> > >   	int ret;
> > > @@ -997,6 +997,8 @@ static int vchiq_irq_queue_bulk_tx_rx(struct vchiq_instance *instance,
> > >   			"found bulk_waiter %pK for pid %d", waiter,
> > >   			current->pid);
> > >   		userdata = &waiter->bulk_waiter;
> > > +	} else {
> > > +		userdata = args->userdata;
> > 
> > "args->userdata" is marked as a user pointer so we really don't want to
> > mix user and kernel pointers here.  Presumably this opens up a large
> > security hole.
> 
> It's an opaque, pointer-sized token that only exists to bereturned to userspace (or not,
> without this patch) - it's hard to see that as a security hole.

I was assuming the bug here was a NULL dereference...  Apparently that's
not the case?  The commit message needs to be updated to be more clear
about how the bug looks like to the user.

Are we using the "&waiter->bulk_waiter" as a "token to be returned to
userspace" as well?  It looks like maybe it is in vchiq_put_completion().
That defeats KASLR and is a different sort of security problem.

Mixing __user pointers and regular pointers is dangerous and has lead to
security problems in this driver in the past.  But also mixing mixing
tokens with pointers just makes the code hard to read.  Instead of
undoing Arnd's work where he split the user space and kernel pointers
apart we should go ahead and spit it up even more.  At least add a giant
FIXME comment and an item in the TODO list so we don't forget to do this
before removing the code from staging.

regards,
dan carpenter

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

  reply	other threads:[~2021-01-05 11:04 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-01-04 12:09 [PATCH 0/2] A brace of vchiq bulk transfer fixes Phil Elwell
2021-01-04 12:09 ` Phil Elwell
2021-01-04 12:09 ` [PATCH 1/2] staging: vchiq: Fix bulk userdata handling Phil Elwell
2021-01-04 12:09   ` Phil Elwell
2021-01-04 17:37   ` Stefan Wahren
2021-01-04 17:37     ` Stefan Wahren
2021-01-04 18:31   ` Dan Carpenter
2021-01-04 18:31     ` Dan Carpenter
2021-01-04 19:26     ` Phil Elwell
2021-01-04 19:26       ` Phil Elwell
2021-01-05 11:01       ` Dan Carpenter [this message]
2021-01-05 11:01         ` Dan Carpenter
2021-01-05 11:53         ` Phil Elwell
2021-01-05 11:53           ` Phil Elwell
2021-01-05 13:22           ` Dan Carpenter
2021-01-05 13:22             ` Dan Carpenter
2021-01-05 15:13           ` Arnd Bergmann
2021-01-05 15:13             ` Arnd Bergmann
2021-01-04 12:09 ` [PATCH 2/2] staging: vchiq: Fix bulk transfers on 64-bit builds Phil Elwell
2021-01-04 12:09   ` Phil Elwell

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=20210105110140.GW2809@kadam \
    --to=dan.carpenter@oracle.com \
    --cc=arnd@arndb.de \
    --cc=bcm-kernel-feedback-list@broadcom.com \
    --cc=devel@driverdev.osuosl.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-rpi-kernel@lists.infradead.org \
    --cc=nsaenzjulienne@suse.de \
    --cc=phil@raspberrypi.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 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.