All of lore.kernel.org
 help / color / mirror / Atom feed
From: Eric Dumazet <edumazet@kernel.org>
To: "David S . Miller" <davem@davemloft.net>,
	Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
	Willem de Bruijn <willemb@google.com>
Cc: Kuniyuki Iwashima <kuniyu@google.com>,
	Simon Horman <horms@kernel.org>,
	netdev@vger.kernel.org, Eric Dumazet <edumazet@kernel.org>
Subject: [PATCH net-next 4/4] tap: remove tap_get_tap_dev() and tap_put_tap_dev()
Date: Thu, 19 Nov 2026 08:22:58 +0100	[thread overview]
Message-ID: <20261119072258.3157902-5-edumazet@kernel.org> (raw)
In-Reply-To: <20261119072258.3157902-1-edumazet@kernel.org>

tap_get_tap_dev() takes a reference on tap->dev, released by
tap_put_tap_dev().

This comes from commit 8f475a318aaa ("macvtap: introduce
macvtap_get_vlan()"), when q->vlan was read under rcu_read_lock_bh()
and the reference was needed to use the device after
rcu_read_unlock_bh().

Both remaining callers, SIOCGIFHWADDR and SIOCSIFHWADDR, hold RTNL
for the whole time the device is used. tap_del_queues() clears q->tap
under RTNL, before the device can be freed, so a non NULL q->tap
guarantees the device stays around until rtnl_unlock(). TUNSETOFFLOAD
already relies on this.

Use rtnl_dereference(q->tap) directly.

Signed-off-by: Eric Dumazet <edumazet@kernel.org>
---
 drivers/net/tap.c | 23 ++---------------------
 1 file changed, 2 insertions(+), 21 deletions(-)

diff --git a/drivers/net/tap.c b/drivers/net/tap.c
index a240609d2a8a6b643216135d4b80540c18cf11db..2d6af83d97b38e5dd9137c02e5bf002a1d12f678 100644
--- a/drivers/net/tap.c
+++ b/drivers/net/tap.c
@@ -866,23 +866,6 @@ static ssize_t tap_read_iter(struct kiocb *iocb, struct iov_iter *to)
 	return ret;
 }
 
-static struct tap_dev *tap_get_tap_dev(struct tap_queue *q)
-{
-	struct tap_dev *tap;
-
-	ASSERT_RTNL();
-	tap = rtnl_dereference(q->tap);
-	if (tap)
-		dev_hold(tap->dev);
-
-	return tap;
-}
-
-static void tap_put_tap_dev(struct tap_dev *tap)
-{
-	dev_put(tap->dev);
-}
-
 static int tap_ioctl_set_queue(struct file *file, unsigned int flags)
 {
 	struct tap_queue *q = file->private_data;
@@ -1040,7 +1023,7 @@ static long tap_ioctl(struct file *file, unsigned int cmd,
 
 	case SIOCGIFHWADDR:
 		rtnl_lock();
-		tap = tap_get_tap_dev(q);
+		tap = rtnl_dereference(q->tap);
 		if (!tap) {
 			rtnl_unlock();
 			return -ENOLINK;
@@ -1051,7 +1034,6 @@ static long tap_ioctl(struct file *file, unsigned int cmd,
 		if (copy_to_user(&ifr->ifr_name, tap->dev->name, IFNAMSIZ) ||
 		    copy_to_user(&ifr->ifr_hwaddr, &ss, sizeof(ifr->ifr_hwaddr)))
 			ret = -EFAULT;
-		tap_put_tap_dev(tap);
 		rtnl_unlock();
 		return ret;
 
@@ -1059,7 +1041,7 @@ static long tap_ioctl(struct file *file, unsigned int cmd,
 		if (copy_from_user(&ss, &ifr->ifr_hwaddr, sizeof(ifr->ifr_hwaddr)))
 			return -EFAULT;
 		rtnl_lock();
-		tap = tap_get_tap_dev(q);
+		tap = rtnl_dereference(q->tap);
 		if (!tap) {
 			rtnl_unlock();
 			return -ENOLINK;
@@ -1068,7 +1050,6 @@ static long tap_ioctl(struct file *file, unsigned int cmd,
 			ret = -EINVAL;
 		else
 			ret = dev_set_mac_address_user(tap->dev, &ss, NULL);
-		tap_put_tap_dev(tap);
 		rtnl_unlock();
 		return ret;
 
-- 
2.53.0


  parent reply	other threads:[~2026-11-19  7:23 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-19  7:22 [PATCH net-next 0/4] tap: do not hold RTNL in open(), release() and queue ioctls Eric Dumazet
2026-11-19  7:22 ` [PATCH net-next 1/4] tap: detach queues from the NETDEV_UNREGISTER notifier Eric Dumazet
2026-11-19 23:46   ` Willem de Bruijn
2026-11-19  7:22 ` [PATCH net-next 2/4] tap: add a mutex to protect queue management Eric Dumazet
2026-11-19 23:49   ` Willem de Bruijn
2026-11-19  7:22 ` [PATCH net-next 3/4] tap: do not hold RTNL in open(), release() and queue ioctls Eric Dumazet
2026-11-19  7:22 ` Eric Dumazet [this message]
2026-11-20  0:03   ` [PATCH net-next 4/4] tap: remove tap_get_tap_dev() and tap_put_tap_dev() Willem de Bruijn

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=20261119072258.3157902-5-edumazet@kernel.org \
    --to=edumazet@kernel.org \
    --cc=davem@davemloft.net \
    --cc=horms@kernel.org \
    --cc=kuba@kernel.org \
    --cc=kuniyu@google.com \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=willemb@google.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.