netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH AUTOSEL 4.19 03/21] net: fec_mpc52xx_phy: Use %pa to format resource_size_t
       [not found] <20241124135709.3351371-1-sashal@kernel.org>
@ 2024-11-24 13:56 ` Sasha Levin
  2024-11-24 13:56 ` [PATCH AUTOSEL 4.19 04/21] net: ethernet: fs_enet: " Sasha Levin
                   ` (6 subsequent siblings)
  7 siblings, 0 replies; 8+ messages in thread
From: Sasha Levin @ 2024-11-24 13:56 UTC (permalink / raw)
  To: linux-kernel, stable
  Cc: Simon Horman, Geert Uytterhoeven, Daniel Machon, Jakub Kicinski,
	Sasha Levin, andrew+netdev, davem, edumazet, pabeni,
	u.kleine-koenig, netdev

From: Simon Horman <horms@kernel.org>

[ Upstream commit 020bfdc4ed94be472138c891bde4d14241cf00fd ]

The correct format string for resource_size_t is %pa which
acts on the address of the variable to be formatted [1].

[1] https://elixir.bootlin.com/linux/v6.11.3/source/Documentation/core-api/printk-formats.rst#L229

Introduced by commit 9d9326d3bc0e ("phy: Change mii_bus id field to a string")

Flagged by gcc-14 as:

drivers/net/ethernet/freescale/fec_mpc52xx_phy.c: In function 'mpc52xx_fec_mdio_probe':
drivers/net/ethernet/freescale/fec_mpc52xx_phy.c:97:46: warning: format '%x' expects argument of type 'unsigned int', but argument 4 has type 'resource_size_t' {aka 'long long unsigned int'} [-Wformat=]
   97 |         snprintf(bus->id, MII_BUS_ID_SIZE, "%x", res.start);
      |                                             ~^   ~~~~~~~~~
      |                                              |      |
      |                                              |      resource_size_t {aka long long unsigned int}
      |                                              unsigned int
      |                                             %llx

No functional change intended.
Compile tested only.

Reported-by: Geert Uytterhoeven <geert@linux-m68k.org>
Closes: https://lore.kernel.org/netdev/711d7f6d-b785-7560-f4dc-c6aad2cce99@linux-m68k.org/
Signed-off-by: Simon Horman <horms@kernel.org>
Reviewed-by: Daniel Machon <daniel.machon@microchip.com>
Link: https://patch.msgid.link/20241014-net-pa-fmt-v1-1-dcc9afb8858b@kernel.org
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
 drivers/net/ethernet/freescale/fec_mpc52xx_phy.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/freescale/fec_mpc52xx_phy.c b/drivers/net/ethernet/freescale/fec_mpc52xx_phy.c
index b5497e3083020..7e631e2f710fb 100644
--- a/drivers/net/ethernet/freescale/fec_mpc52xx_phy.c
+++ b/drivers/net/ethernet/freescale/fec_mpc52xx_phy.c
@@ -92,7 +92,7 @@ static int mpc52xx_fec_mdio_probe(struct platform_device *of)
 		goto out_free;
 	}
 
-	snprintf(bus->id, MII_BUS_ID_SIZE, "%x", res.start);
+	snprintf(bus->id, MII_BUS_ID_SIZE, "%pa", &res.start);
 	bus->priv = priv;
 
 	bus->parent = dev;
-- 
2.43.0


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

* [PATCH AUTOSEL 4.19 04/21] net: ethernet: fs_enet: Use %pa to format resource_size_t
       [not found] <20241124135709.3351371-1-sashal@kernel.org>
  2024-11-24 13:56 ` [PATCH AUTOSEL 4.19 03/21] net: fec_mpc52xx_phy: Use %pa to format resource_size_t Sasha Levin
@ 2024-11-24 13:56 ` Sasha Levin
  2024-11-24 13:56 ` [PATCH AUTOSEL 4.19 05/21] af_packet: avoid erroring out after sock_init_data() in packet_create() Sasha Levin
                   ` (5 subsequent siblings)
  7 siblings, 0 replies; 8+ messages in thread
From: Sasha Levin @ 2024-11-24 13:56 UTC (permalink / raw)
  To: linux-kernel, stable
  Cc: Simon Horman, Geert Uytterhoeven, Daniel Machon, Jakub Kicinski,
	Sasha Levin, pantelis.antoniou, andrew+netdev, davem, edumazet,
	pabeni, linuxppc-dev, netdev

From: Simon Horman <horms@kernel.org>

[ Upstream commit 45fe45fada261e1e83fce2a07fa22835aec1cf0a ]

The correct format string for resource_size_t is %pa which
acts on the address of the variable to be formatted [1].

[1] https://elixir.bootlin.com/linux/v6.11.3/source/Documentation/core-api/printk-formats.rst#L229

Introduced by commit 9d9326d3bc0e ("phy: Change mii_bus id field to a string")

Flagged by gcc-14 as:

drivers/net/ethernet/freescale/fs_enet/mii-bitbang.c: In function 'fs_mii_bitbang_init':
drivers/net/ethernet/freescale/fs_enet/mii-bitbang.c:126:46: warning: format '%x' expects argument of type 'unsigned int', but argument 4 has type 'resource_size_t' {aka 'long long unsigned int'} [-Wformat=]
  126 |         snprintf(bus->id, MII_BUS_ID_SIZE, "%x", res.start);
      |                                             ~^   ~~~~~~~~~
      |                                              |      |
      |                                              |      resource_size_t {aka long long unsigned int}
      |                                              unsigned int
      |                                             %llx

No functional change intended.
Compile tested only.

Reported-by: Geert Uytterhoeven <geert@linux-m68k.org>
Closes: https://lore.kernel.org/netdev/711d7f6d-b785-7560-f4dc-c6aad2cce99@linux-m68k.org/
Signed-off-by: Simon Horman <horms@kernel.org>
Reviewed-by: Daniel Machon <daniel.machon@microchip.com>
Link: https://patch.msgid.link/20241014-net-pa-fmt-v1-2-dcc9afb8858b@kernel.org
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
 drivers/net/ethernet/freescale/fs_enet/mii-bitbang.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/freescale/fs_enet/mii-bitbang.c b/drivers/net/ethernet/freescale/fs_enet/mii-bitbang.c
index 21de56345503f..f743112730194 100644
--- a/drivers/net/ethernet/freescale/fs_enet/mii-bitbang.c
+++ b/drivers/net/ethernet/freescale/fs_enet/mii-bitbang.c
@@ -126,7 +126,7 @@ static int fs_mii_bitbang_init(struct mii_bus *bus, struct device_node *np)
 	 * we get is an int, and the odds of multiple bitbang mdio buses
 	 * is low enough that it's not worth going too crazy.
 	 */
-	snprintf(bus->id, MII_BUS_ID_SIZE, "%x", res.start);
+	snprintf(bus->id, MII_BUS_ID_SIZE, "%pa", &res.start);
 
 	data = of_get_property(np, "fsl,mdio-pin", &len);
 	if (!data || len != 4)
-- 
2.43.0


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

* [PATCH AUTOSEL 4.19 05/21] af_packet: avoid erroring out after sock_init_data() in packet_create()
       [not found] <20241124135709.3351371-1-sashal@kernel.org>
  2024-11-24 13:56 ` [PATCH AUTOSEL 4.19 03/21] net: fec_mpc52xx_phy: Use %pa to format resource_size_t Sasha Levin
  2024-11-24 13:56 ` [PATCH AUTOSEL 4.19 04/21] net: ethernet: fs_enet: " Sasha Levin
@ 2024-11-24 13:56 ` Sasha Levin
  2024-11-24 13:56 ` [PATCH AUTOSEL 4.19 08/21] net: ieee802154: do not leave a dangling sk pointer in ieee802154_create() Sasha Levin
                   ` (4 subsequent siblings)
  7 siblings, 0 replies; 8+ messages in thread
From: Sasha Levin @ 2024-11-24 13:56 UTC (permalink / raw)
  To: linux-kernel, stable
  Cc: Ignat Korchagin, Eric Dumazet, Kuniyuki Iwashima,
	Willem de Bruijn, Jakub Kicinski, Sasha Levin,
	willemdebruijn.kernel, davem, pabeni, netdev

From: Ignat Korchagin <ignat@cloudflare.com>

[ Upstream commit 46f2a11cb82b657fd15bab1c47821b635e03838b ]

After sock_init_data() the allocated sk object is attached to the provided
sock object. On error, packet_create() frees the sk object leaving the
dangling pointer in the sock object on return. Some other code may try
to use this pointer and cause use-after-free.

Suggested-by: Eric Dumazet <edumazet@google.com>
Signed-off-by: Ignat Korchagin <ignat@cloudflare.com>
Reviewed-by: Kuniyuki Iwashima <kuniyu@amazon.com>
Reviewed-by: Willem de Bruijn <willemb@google.com>
Reviewed-by: Eric Dumazet <edumazet@google.com>
Link: https://patch.msgid.link/20241014153808.51894-2-ignat@cloudflare.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
 net/packet/af_packet.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/net/packet/af_packet.c b/net/packet/af_packet.c
index b285a6e1a7669..31b2a843611be 100644
--- a/net/packet/af_packet.c
+++ b/net/packet/af_packet.c
@@ -3346,18 +3346,18 @@ static int packet_create(struct net *net, struct socket *sock, int protocol,
 	if (sock->type == SOCK_PACKET)
 		sock->ops = &packet_ops_spkt;
 
+	po = pkt_sk(sk);
+	err = packet_alloc_pending(po);
+	if (err)
+		goto out_sk_free;
+
 	sock_init_data(sock, sk);
 
-	po = pkt_sk(sk);
 	init_completion(&po->skb_completion);
 	sk->sk_family = PF_PACKET;
 	po->num = proto;
 	po->xmit = dev_queue_xmit;
 
-	err = packet_alloc_pending(po);
-	if (err)
-		goto out2;
-
 	packet_cached_dev_reset(po);
 
 	sk->sk_destruct = packet_sock_destruct;
@@ -3392,7 +3392,7 @@ static int packet_create(struct net *net, struct socket *sock, int protocol,
 	preempt_enable();
 
 	return 0;
-out2:
+out_sk_free:
 	sk_free(sk);
 out:
 	return err;
-- 
2.43.0


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

* [PATCH AUTOSEL 4.19 08/21] net: ieee802154: do not leave a dangling sk pointer in ieee802154_create()
       [not found] <20241124135709.3351371-1-sashal@kernel.org>
                   ` (2 preceding siblings ...)
  2024-11-24 13:56 ` [PATCH AUTOSEL 4.19 05/21] af_packet: avoid erroring out after sock_init_data() in packet_create() Sasha Levin
@ 2024-11-24 13:56 ` Sasha Levin
  2024-11-24 13:56 ` [PATCH AUTOSEL 4.19 09/21] net: inet: do not leave a dangling sk pointer in inet_create() Sasha Levin
                   ` (3 subsequent siblings)
  7 siblings, 0 replies; 8+ messages in thread
From: Sasha Levin @ 2024-11-24 13:56 UTC (permalink / raw)
  To: linux-kernel, stable
  Cc: Ignat Korchagin, Miquel Raynal, Kuniyuki Iwashima, Eric Dumazet,
	Jakub Kicinski, Sasha Levin, alex.aring, stefan, davem, pabeni,
	linux-wpan, netdev

From: Ignat Korchagin <ignat@cloudflare.com>

[ Upstream commit b4fcd63f6ef79c73cafae8cf4a114def5fc3d80d ]

sock_init_data() attaches the allocated sk object to the provided sock
object. If ieee802154_create() fails later, the allocated sk object is
freed, but the dangling pointer remains in the provided sock object, which
may allow use-after-free.

Clear the sk pointer in the sock object on error.

Signed-off-by: Ignat Korchagin <ignat@cloudflare.com>
Reviewed-by: Miquel Raynal <miquel.raynal@bootlin.com>
Reviewed-by: Kuniyuki Iwashima <kuniyu@amazon.com>
Reviewed-by: Eric Dumazet <edumazet@google.com>
Link: https://patch.msgid.link/20241014153808.51894-6-ignat@cloudflare.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
 net/ieee802154/socket.c | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/net/ieee802154/socket.c b/net/ieee802154/socket.c
index ee1536de5fca4..5dba3341e3f1f 100644
--- a/net/ieee802154/socket.c
+++ b/net/ieee802154/socket.c
@@ -1065,19 +1065,21 @@ static int ieee802154_create(struct net *net, struct socket *sock,
 
 	if (sk->sk_prot->hash) {
 		rc = sk->sk_prot->hash(sk);
-		if (rc) {
-			sk_common_release(sk);
-			goto out;
-		}
+		if (rc)
+			goto out_sk_release;
 	}
 
 	if (sk->sk_prot->init) {
 		rc = sk->sk_prot->init(sk);
 		if (rc)
-			sk_common_release(sk);
+			goto out_sk_release;
 	}
 out:
 	return rc;
+out_sk_release:
+	sk_common_release(sk);
+	sock->sk = NULL;
+	goto out;
 }
 
 static const struct net_proto_family ieee802154_family_ops = {
-- 
2.43.0


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

* [PATCH AUTOSEL 4.19 09/21] net: inet: do not leave a dangling sk pointer in inet_create()
       [not found] <20241124135709.3351371-1-sashal@kernel.org>
                   ` (3 preceding siblings ...)
  2024-11-24 13:56 ` [PATCH AUTOSEL 4.19 08/21] net: ieee802154: do not leave a dangling sk pointer in ieee802154_create() Sasha Levin
@ 2024-11-24 13:56 ` Sasha Levin
  2024-11-24 13:56 ` [PATCH AUTOSEL 4.19 10/21] net: inet6: do not leave a dangling sk pointer in inet6_create() Sasha Levin
                   ` (2 subsequent siblings)
  7 siblings, 0 replies; 8+ messages in thread
From: Sasha Levin @ 2024-11-24 13:56 UTC (permalink / raw)
  To: linux-kernel, stable
  Cc: Ignat Korchagin, Kuniyuki Iwashima, Eric Dumazet, Jakub Kicinski,
	Sasha Levin, davem, dsahern, pabeni, netdev

From: Ignat Korchagin <ignat@cloudflare.com>

[ Upstream commit 9365fa510c6f82e3aa550a09d0c5c6b44dbc78ff ]

sock_init_data() attaches the allocated sk object to the provided sock
object. If inet_create() fails later, the sk object is freed, but the
sock object retains the dangling pointer, which may create use-after-free
later.

Clear the sk pointer in the sock object on error.

Signed-off-by: Ignat Korchagin <ignat@cloudflare.com>
Reviewed-by: Kuniyuki Iwashima <kuniyu@amazon.com>
Reviewed-by: Eric Dumazet <edumazet@google.com>
Link: https://patch.msgid.link/20241014153808.51894-7-ignat@cloudflare.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
 net/ipv4/af_inet.c | 22 ++++++++++------------
 1 file changed, 10 insertions(+), 12 deletions(-)

diff --git a/net/ipv4/af_inet.c b/net/ipv4/af_inet.c
index 94af34484b8e9..73e805d00f6f7 100644
--- a/net/ipv4/af_inet.c
+++ b/net/ipv4/af_inet.c
@@ -369,32 +369,30 @@ static int inet_create(struct net *net, struct socket *sock, int protocol,
 		inet->inet_sport = htons(inet->inet_num);
 		/* Add to protocol hash chains. */
 		err = sk->sk_prot->hash(sk);
-		if (err) {
-			sk_common_release(sk);
-			goto out;
-		}
+		if (err)
+			goto out_sk_release;
 	}
 
 	if (sk->sk_prot->init) {
 		err = sk->sk_prot->init(sk);
-		if (err) {
-			sk_common_release(sk);
-			goto out;
-		}
+		if (err)
+			goto out_sk_release;
 	}
 
 	if (!kern) {
 		err = BPF_CGROUP_RUN_PROG_INET_SOCK(sk);
-		if (err) {
-			sk_common_release(sk);
-			goto out;
-		}
+		if (err)
+			goto out_sk_release;
 	}
 out:
 	return err;
 out_rcu_unlock:
 	rcu_read_unlock();
 	goto out;
+out_sk_release:
+	sk_common_release(sk);
+	sock->sk = NULL;
+	goto out;
 }
 
 
-- 
2.43.0


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

* [PATCH AUTOSEL 4.19 10/21] net: inet6: do not leave a dangling sk pointer in inet6_create()
       [not found] <20241124135709.3351371-1-sashal@kernel.org>
                   ` (4 preceding siblings ...)
  2024-11-24 13:56 ` [PATCH AUTOSEL 4.19 09/21] net: inet: do not leave a dangling sk pointer in inet_create() Sasha Levin
@ 2024-11-24 13:56 ` Sasha Levin
  2024-11-24 13:56 ` [PATCH AUTOSEL 4.19 20/21] rocker: fix link status detection in rocker_carrier_init() Sasha Levin
  2024-11-24 13:56 ` [PATCH AUTOSEL 4.19 21/21] netpoll: Use rcu_access_pointer() in __netpoll_setup Sasha Levin
  7 siblings, 0 replies; 8+ messages in thread
From: Sasha Levin @ 2024-11-24 13:56 UTC (permalink / raw)
  To: linux-kernel, stable
  Cc: Ignat Korchagin, Kuniyuki Iwashima, Eric Dumazet, Jakub Kicinski,
	Sasha Levin, davem, dsahern, pabeni, netdev

From: Ignat Korchagin <ignat@cloudflare.com>

[ Upstream commit 9df99c395d0f55fb444ef39f4d6f194ca437d884 ]

sock_init_data() attaches the allocated sk pointer to the provided sock
object. If inet6_create() fails later, the sk object is released, but the
sock object retains the dangling sk pointer, which may cause use-after-free
later.

Clear the sock sk pointer on error.

Signed-off-by: Ignat Korchagin <ignat@cloudflare.com>
Reviewed-by: Kuniyuki Iwashima <kuniyu@amazon.com>
Reviewed-by: Eric Dumazet <edumazet@google.com>
Link: https://patch.msgid.link/20241014153808.51894-8-ignat@cloudflare.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
 net/ipv6/af_inet6.c | 22 ++++++++++------------
 1 file changed, 10 insertions(+), 12 deletions(-)

diff --git a/net/ipv6/af_inet6.c b/net/ipv6/af_inet6.c
index f480436b84339..2de90056bdf22 100644
--- a/net/ipv6/af_inet6.c
+++ b/net/ipv6/af_inet6.c
@@ -253,31 +253,29 @@ static int inet6_create(struct net *net, struct socket *sock, int protocol,
 		 */
 		inet->inet_sport = htons(inet->inet_num);
 		err = sk->sk_prot->hash(sk);
-		if (err) {
-			sk_common_release(sk);
-			goto out;
-		}
+		if (err)
+			goto out_sk_release;
 	}
 	if (sk->sk_prot->init) {
 		err = sk->sk_prot->init(sk);
-		if (err) {
-			sk_common_release(sk);
-			goto out;
-		}
+		if (err)
+			goto out_sk_release;
 	}
 
 	if (!kern) {
 		err = BPF_CGROUP_RUN_PROG_INET_SOCK(sk);
-		if (err) {
-			sk_common_release(sk);
-			goto out;
-		}
+		if (err)
+			goto out_sk_release;
 	}
 out:
 	return err;
 out_rcu_unlock:
 	rcu_read_unlock();
 	goto out;
+out_sk_release:
+	sk_common_release(sk);
+	sock->sk = NULL;
+	goto out;
 }
 
 static int __inet6_bind(struct sock *sk, struct sockaddr *uaddr, int addr_len,
-- 
2.43.0


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

* [PATCH AUTOSEL 4.19 20/21] rocker: fix link status detection in rocker_carrier_init()
       [not found] <20241124135709.3351371-1-sashal@kernel.org>
                   ` (5 preceding siblings ...)
  2024-11-24 13:56 ` [PATCH AUTOSEL 4.19 10/21] net: inet6: do not leave a dangling sk pointer in inet6_create() Sasha Levin
@ 2024-11-24 13:56 ` Sasha Levin
  2024-11-24 13:56 ` [PATCH AUTOSEL 4.19 21/21] netpoll: Use rcu_access_pointer() in __netpoll_setup Sasha Levin
  7 siblings, 0 replies; 8+ messages in thread
From: Sasha Levin @ 2024-11-24 13:56 UTC (permalink / raw)
  To: linux-kernel, stable
  Cc: Dmitry Antipov, Jakub Kicinski, Sasha Levin, jiri, andrew+netdev,
	davem, edumazet, pabeni, netdev

From: Dmitry Antipov <dmantipov@yandex.ru>

[ Upstream commit e64285ff41bb7a934bd815bd38f31119be62ac37 ]

Since '1 << rocker_port->pport' may be undefined for port >= 32,
cast the left operand to 'unsigned long long' like it's done in
'rocker_port_set_enable()' above. Compile tested only.

Found by Linux Verification Center (linuxtesting.org) with SVACE.

Signed-off-by: Dmitry Antipov <dmantipov@yandex.ru>
Link: https://patch.msgid.link/20241114151946.519047-1-dmantipov@yandex.ru
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
 drivers/net/ethernet/rocker/rocker_main.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/rocker/rocker_main.c b/drivers/net/ethernet/rocker/rocker_main.c
index 7d81de57b6f4c..184aceaf34e73 100644
--- a/drivers/net/ethernet/rocker/rocker_main.c
+++ b/drivers/net/ethernet/rocker/rocker_main.c
@@ -2535,7 +2535,7 @@ static void rocker_carrier_init(const struct rocker_port *rocker_port)
 	u64 link_status = rocker_read64(rocker, PORT_PHYS_LINK_STATUS);
 	bool link_up;
 
-	link_up = link_status & (1 << rocker_port->pport);
+	link_up = link_status & (1ULL << rocker_port->pport);
 	if (link_up)
 		netif_carrier_on(rocker_port->dev);
 	else
-- 
2.43.0


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

* [PATCH AUTOSEL 4.19 21/21] netpoll: Use rcu_access_pointer() in __netpoll_setup
       [not found] <20241124135709.3351371-1-sashal@kernel.org>
                   ` (6 preceding siblings ...)
  2024-11-24 13:56 ` [PATCH AUTOSEL 4.19 20/21] rocker: fix link status detection in rocker_carrier_init() Sasha Levin
@ 2024-11-24 13:56 ` Sasha Levin
  7 siblings, 0 replies; 8+ messages in thread
From: Sasha Levin @ 2024-11-24 13:56 UTC (permalink / raw)
  To: linux-kernel, stable
  Cc: Breno Leitao, Michal Kubiak, Jakub Kicinski, Sasha Levin, davem,
	edumazet, pabeni, horms, viro, netdev

From: Breno Leitao <leitao@debian.org>

[ Upstream commit c69c5e10adb903ae2438d4f9c16eccf43d1fcbc1 ]

The ndev->npinfo pointer in __netpoll_setup() is RCU-protected but is being
accessed directly for a NULL check. While no RCU read lock is held in this
context, we should still use proper RCU primitives for consistency and
correctness.

Replace the direct NULL check with rcu_access_pointer(), which is the
appropriate primitive when only checking for NULL without dereferencing
the pointer. This function provides the necessary ordering guarantees
without requiring RCU read-side protection.

Reviewed-by: Michal Kubiak <michal.kubiak@intel.com>
Signed-off-by: Breno Leitao <leitao@debian.org>
Link: https://patch.msgid.link/20241118-netpoll_rcu-v1-1-a1888dcb4a02@debian.org
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
 net/core/netpoll.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/net/core/netpoll.c b/net/core/netpoll.c
index 08f0da9e6a809..0df6ae0fb71e5 100644
--- a/net/core/netpoll.c
+++ b/net/core/netpoll.c
@@ -616,7 +616,7 @@ int __netpoll_setup(struct netpoll *np, struct net_device *ndev)
 		goto out;
 	}
 
-	if (!ndev->npinfo) {
+	if (!rcu_access_pointer(ndev->npinfo)) {
 		npinfo = kmalloc(sizeof(*npinfo), GFP_KERNEL);
 		if (!npinfo) {
 			err = -ENOMEM;
-- 
2.43.0


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

end of thread, other threads:[~2024-11-24 13:57 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <20241124135709.3351371-1-sashal@kernel.org>
2024-11-24 13:56 ` [PATCH AUTOSEL 4.19 03/21] net: fec_mpc52xx_phy: Use %pa to format resource_size_t Sasha Levin
2024-11-24 13:56 ` [PATCH AUTOSEL 4.19 04/21] net: ethernet: fs_enet: " Sasha Levin
2024-11-24 13:56 ` [PATCH AUTOSEL 4.19 05/21] af_packet: avoid erroring out after sock_init_data() in packet_create() Sasha Levin
2024-11-24 13:56 ` [PATCH AUTOSEL 4.19 08/21] net: ieee802154: do not leave a dangling sk pointer in ieee802154_create() Sasha Levin
2024-11-24 13:56 ` [PATCH AUTOSEL 4.19 09/21] net: inet: do not leave a dangling sk pointer in inet_create() Sasha Levin
2024-11-24 13:56 ` [PATCH AUTOSEL 4.19 10/21] net: inet6: do not leave a dangling sk pointer in inet6_create() Sasha Levin
2024-11-24 13:56 ` [PATCH AUTOSEL 4.19 20/21] rocker: fix link status detection in rocker_carrier_init() Sasha Levin
2024-11-24 13:56 ` [PATCH AUTOSEL 4.19 21/21] netpoll: Use rcu_access_pointer() in __netpoll_setup Sasha Levin

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