netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net-next 2/2] devlink: Fix list access without lock while reading region
@ 2019-02-12  7:09 Parav Pandit
  2019-02-12  9:01 ` Sergei Shtylyov
  0 siblings, 1 reply; 3+ messages in thread
From: Parav Pandit @ 2019-02-12  7:09 UTC (permalink / raw)
  To: jiri, davem, netdev; +Cc: parav

While finding the devlink device during region reading,
devlink device list is accessed and devlink device is
returned without holding a lock. This could lead to user-after-free
accesses.

While at it, add lockdep assert to ensure that all future callers hold
the lock when calling devlink_get_from_attrs().

Fixes: 4e54795a27f5 ("devlink: Add support for region snapshot read command")
Signed-off-by: Parav Pandit <parav@mellanox.com>
Acked-by: Jiri Pirko <jiri@mellanox.com>
---
 net/core/devlink.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/net/core/devlink.c b/net/core/devlink.c
index 8a198ba..8cd773b 100644
--- a/net/core/devlink.c
+++ b/net/core/devlink.c
@@ -116,6 +116,8 @@ static struct devlink *devlink_get_from_attrs(struct net *net,
 	busname = nla_data(attrs[DEVLINK_ATTR_BUS_NAME]);
 	devname = nla_data(attrs[DEVLINK_ATTR_DEV_NAME]);
 
+	lockdep_assert_held(&devlink_mutex);
+
 	list_for_each_entry(devlink, &devlink_list, list) {
 		if (strcmp(devlink->dev->bus->name, busname) == 0 &&
 		    strcmp(dev_name(devlink->dev), devname) == 0 &&
@@ -3642,13 +3644,13 @@ static int devlink_nl_cmd_region_read_dumpit(struct sk_buff *skb,
 	if (err)
 		goto out;
 
+	mutex_lock(&devlink_mutex);
 	devlink = devlink_get_from_attrs(sock_net(cb->skb->sk), attrs);
 	if (IS_ERR(devlink)) {
 		err = -ENODEV;
-		goto out;
+		goto out_dev;
 	}
 
-	mutex_lock(&devlink_mutex);
 	mutex_lock(&devlink->lock);
 
 	if (!attrs[DEVLINK_ATTR_REGION_NAME] ||
@@ -3723,6 +3725,7 @@ static int devlink_nl_cmd_region_read_dumpit(struct sk_buff *skb,
 	genlmsg_cancel(skb, hdr);
 out_unlock:
 	mutex_unlock(&devlink->lock);
+out_dev:
 	mutex_unlock(&devlink_mutex);
 out:
 	return err;
-- 
1.8.3.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH net-next 2/2] devlink: Fix list access without lock while reading region
  2019-02-12  7:09 [PATCH net-next 2/2] devlink: Fix list access without lock while reading region Parav Pandit
@ 2019-02-12  9:01 ` Sergei Shtylyov
  2019-02-12 16:04   ` Parav Pandit
  0 siblings, 1 reply; 3+ messages in thread
From: Sergei Shtylyov @ 2019-02-12  9:01 UTC (permalink / raw)
  To: Parav Pandit, jiri, davem, netdev

Hello!

On 12.02.2019 10:09, Parav Pandit wrote:

> While finding the devlink device during region reading,
> devlink device list is accessed and devlink device is
> returned without holding a lock. This could lead to user-after-free

    Use-after-free, perhaps?

> accesses.
> 
> While at it, add lockdep assert to ensure that all future callers hold
> the lock when calling devlink_get_from_attrs().
> 
> Fixes: 4e54795a27f5 ("devlink: Add support for region snapshot read command")
> Signed-off-by: Parav Pandit <parav@mellanox.com>
> Acked-by: Jiri Pirko <jiri@mellanox.com>
[...]

MBR, Sergei

^ permalink raw reply	[flat|nested] 3+ messages in thread

* RE: [PATCH net-next 2/2] devlink: Fix list access without lock while reading region
  2019-02-12  9:01 ` Sergei Shtylyov
@ 2019-02-12 16:04   ` Parav Pandit
  0 siblings, 0 replies; 3+ messages in thread
From: Parav Pandit @ 2019-02-12 16:04 UTC (permalink / raw)
  To: Sergei Shtylyov, Jiri Pirko, davem, netdev



> -----Original Message-----
> From: Sergei Shtylyov <sergei.shtylyov@cogentembedded.com>
> Sent: Tuesday, February 12, 2019 3:01 AM
> To: Parav Pandit <parav@mellanox.com>; Jiri Pirko <jiri@mellanox.com>;
> davem@davemloft.net; netdev@vger.kernel.org
> Subject: Re: [PATCH net-next 2/2] devlink: Fix list access without lock while
> reading region
> 
> Hello!
> 
> On 12.02.2019 10:09, Parav Pandit wrote:
> 
> > While finding the devlink device during region reading, devlink device
> > list is accessed and devlink device is returned without holding a
> > lock. This could lead to user-after-free
> 
>     Use-after-free, perhaps?
> 
Yep. Sending v1 to fix typo.

> > accesses.
> >
> > While at it, add lockdep assert to ensure that all future callers hold
> > the lock when calling devlink_get_from_attrs().
> >
> > Fixes: 4e54795a27f5 ("devlink: Add support for region snapshot read
> > command")
> > Signed-off-by: Parav Pandit <parav@mellanox.com>
> > Acked-by: Jiri Pirko <jiri@mellanox.com>
> [...]
> 
> MBR, Sergei

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2019-02-12 16:04 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-02-12  7:09 [PATCH net-next 2/2] devlink: Fix list access without lock while reading region Parav Pandit
2019-02-12  9:01 ` Sergei Shtylyov
2019-02-12 16:04   ` Parav Pandit

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).