mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] net: bonding: fix NULL pointer dereference in bond_do_ioctl()
@ 2026-06-01  8:56 ZhaoJinming
  2026-06-04  9:50 ` patchwork-bot+netdevbpf
  0 siblings, 1 reply; 2+ messages in thread
From: ZhaoJinming @ 2026-06-01  8:56 UTC (permalink / raw)
  To: Jay Vosburgh, Andrew Lunn, David S. Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni
  Cc: Jarod Wilson, netdev, linux-kernel, ZhaoJinming, stable

In bond_do_ioctl(), slave_dev is obtained via __dev_get_by_name() which
can return NULL if the requested interface name does not exist. However,
the subsequent slave_dbg() call is placed before the NULL check:

    slave_dev = __dev_get_by_name(net, ifr->ifr_slave);
    slave_dbg(bond_dev, slave_dev, "slave_dev=%p:\n", slave_dev); //here
    if (!slave_dev)
        return -ENODEV;

The slave_dbg() macro expands to netdev_dbg(bond_dev, "(slave %s): " fmt,
(slave_dev)->name, ...) which unconditionally dereferences slave_dev->name
before the NULL check is performed. This results in a NULL pointer
dereference kernel oops when a user calls bonding ioctl (e.g. 
SIOCBONDENSLAVE, SIOCBONDRELEASE, etc.) with a non-existent slave 
interface name.

This is reachable from userspace via the bonding ioctl interface with
CAP_NET_ADMIN capability, making it a potential local denial-of-service
vector.

Fix by moving the slave_dbg() call after the NULL check.

Fixes: e2a7420df2e0 ("bonding/main: convert to using slave printk macros")
Cc: stable@vger.kernel.org # v5.2+
Signed-off-by: ZhaoJinming <zhaojinming@uniontech.com>
---
 drivers/net/bonding/bond_main.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/net/bonding/bond_main.c b/drivers/net/bonding/bond_main.c
index 82e779f7916b..8e75453ce0ef 100644
--- a/drivers/net/bonding/bond_main.c
+++ b/drivers/net/bonding/bond_main.c
@@ -4621,11 +4621,11 @@ static int bond_do_ioctl(struct net_device *bond_dev, struct ifreq *ifr, int cmd
 
 	slave_dev = __dev_get_by_name(net, ifr->ifr_slave);
 
-	slave_dbg(bond_dev, slave_dev, "slave_dev=%p:\n", slave_dev);
-
 	if (!slave_dev)
 		return -ENODEV;
 
+	slave_dbg(bond_dev, slave_dev, "slave_dev=%p:\n", slave_dev);
+
 	switch (cmd) {
 	case SIOCBONDENSLAVE:
 		res = bond_enslave(bond_dev, slave_dev, NULL);
-- 
2.20.1


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

* Re: [PATCH] net: bonding: fix NULL pointer dereference in bond_do_ioctl()
  2026-06-01  8:56 [PATCH] net: bonding: fix NULL pointer dereference in bond_do_ioctl() ZhaoJinming
@ 2026-06-04  9:50 ` patchwork-bot+netdevbpf
  0 siblings, 0 replies; 2+ messages in thread
From: patchwork-bot+netdevbpf @ 2026-06-04  9:50 UTC (permalink / raw)
  To: ZhaoJinming
  Cc: jv, andrew+netdev, davem, edumazet, kuba, pabeni, jarod, netdev,
	linux-kernel, stable

Hello:

This patch was applied to netdev/net.git (main)
by Paolo Abeni <pabeni@redhat.com>:

On Mon,  1 Jun 2026 16:56:49 +0800 you wrote:
> In bond_do_ioctl(), slave_dev is obtained via __dev_get_by_name() which
> can return NULL if the requested interface name does not exist. However,
> the subsequent slave_dbg() call is placed before the NULL check:
> 
>     slave_dev = __dev_get_by_name(net, ifr->ifr_slave);
>     slave_dbg(bond_dev, slave_dev, "slave_dev=%p:\n", slave_dev); //here
>     if (!slave_dev)
>         return -ENODEV;
> 
> [...]

Here is the summary with links:
  - net: bonding: fix NULL pointer dereference in bond_do_ioctl()
    https://git.kernel.org/netdev/net/c/a764b0e8317a

You are awesome, thank you!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



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

end of thread, other threads:[~2026-06-04  9:50 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-06-01  8:56 [PATCH] net: bonding: fix NULL pointer dereference in bond_do_ioctl() ZhaoJinming
2026-06-04  9:50 ` patchwork-bot+netdevbpf

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

Powered by JetHome