mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Kory Maincent <kory.maincent@bootlin.com>
To: Jiaming Zhang <r772577952@gmail.com>
Cc: davem@davemloft.net, edumazet@google.com, kuba@kernel.org,
	netdev@vger.kernel.org, pabeni@redhat.com, horms@kernel.org,
	kuniyu@google.com, linux-kernel@vger.kernel.org, sdf@fomichev.me,
	syzkaller@googlegroups.com,
	Vladimir Oltean <vladimir.oltean@nxp.com>
Subject: Re: [Linux Kernel Bug] KASAN: null-ptr-deref Read in generic_hwtstamp_ioctl_lower
Date: Wed, 29 Oct 2025 11:06:51 +0100	[thread overview]
Message-ID: <20251029110651.25c4936d@kmaincent-XPS-13-7390> (raw)
In-Reply-To: <CANypQFZ8KO=eUe7YPC+XdtjOAvdVyRnpFk_V3839ixCbdUNsGA@mail.gmail.com>

Hello Jiaming,

+Vlad

On Wed, 29 Oct 2025 16:45:37 +0800
Jiaming Zhang <r772577952@gmail.com> wrote:

> Dear Linux kernel developers and maintainers,
> 
> We are writing to report a null pointer dereference bug discovered in
> the net subsystem. This bug is reproducible on the latest version
> (v6.18-rc3, commit dcb6fa37fd7bc9c3d2b066329b0d27dedf8becaa).
> 
> The root cause is in tsconfig_prepare_data(), where a local
> kernel_hwtstamp_config struct (cfg) is initialized using {}, setting
> all its members to zero. Consequently, cfg.ifr becomes NULL.
> 
> cfg is then passed as: tsconfig_prepare_data() ->
> dev_get_hwtstamp_phylib() -> vlan_hwtstamp_get() (via
> dev->netdev_ops->ndo_hwtstamp_get) -> generic_hwtstamp_get_lower() ->
> generic_hwtstamp_ioctl_lower().
> 
> The function generic_hwtstamp_ioctl_lower() assumes cfg->ifr is a
> valid pointer and attempts to access cfg->ifr->ifr_ifru. This access
> dereferences the NULL pointer, triggering the bug.

Thanks for spotting this issue!

In the ideal world we would have all Ethernet driver supporting the
hwtstamp_get/set NDOs but that not currently the case.	
Vladimir Oltean was working on this but it is not done yet. 
$ git grep SIOCGHWTSTAMP drivers/net/ethernet | wc -l
16
 
> As a potential fix, we can declare a local struct ifreq variable in
> tsconfig_prepare_data(), zero-initializing it, and then assigning its
> address to cfg.ifr before calling dev_get_hwtstamp_phylib(). This
> ensures that functions down the call chain receive a valid pointer.

If we do that we will have legacy IOCTL path inside the Netlink path and that's
not something we want.
In fact it is possible because the drivers calling
generic_hwtstamp_get/set_lower functions are already converted to hwtstamp NDOs
therefore the NDO check in tsconfig_prepare_data is not working on these case.

IMO the solution is to add a check on the ifr value in the
generic_hwtstamp_set/get_lower functions like that:

int generic_hwtstamp_set_lower(struct net_device *dev,
			       struct kernel_hwtstamp_config *kernel_cfg,
			       struct netlink_ext_ack *extack)
{
...

	/* Netlink path with unconverted lower driver */
	if (!kernel_cfg->ifr)
		return -EOPNOTSUPP;

	/* Legacy path: unconverted lower driver */
	return generic_hwtstamp_ioctl_lower(dev, SIOCSHWTSTAMP, kernel_cfg);
}

Regards,
-- 
Köry Maincent, Bootlin
Embedded Linux and kernel engineering
https://bootlin.com

  reply	other threads:[~2025-10-29 10:06 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-10-29  8:45 Jiaming Zhang
2025-10-29 10:06 ` Kory Maincent [this message]
2025-10-29 12:22   ` Jiaming Zhang
2025-10-29 16:19   ` Vladimir Oltean
2025-10-29 16:47     ` Kory Maincent
2025-10-29 19:28       ` Vadim Fedorenko
2025-10-30  9:36   ` [PATCH] net: core: prevent NULL deref in generic_hwtstamp_ioctl_lower() Jiaming Zhang
2025-10-30 10:14     ` Kory Maincent
2025-10-30 10:49       ` [PATCH v2] " Jiaming Zhang
2025-10-30 12:49       ` [PATCH v3 0/1] " Jiaming Zhang
2025-10-30 12:49         ` [PATCH v3 1/1] " Jiaming Zhang
2025-11-04  1:15           ` Jakub Kicinski
2025-11-11 17:36             ` [PATCH v4 0/1] " Jiaming Zhang
2025-11-11 17:36               ` [PATCH v4 1/1] " Jiaming Zhang
2025-11-12  8:45                 ` Kory Maincent
2025-11-14  1:40               ` [PATCH v4 0/1] " patchwork-bot+netdevbpf

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=20251029110651.25c4936d@kmaincent-XPS-13-7390 \
    --to=kory.maincent@bootlin.com \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=horms@kernel.org \
    --cc=kuba@kernel.org \
    --cc=kuniyu@google.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=r772577952@gmail.com \
    --cc=sdf@fomichev.me \
    --cc=syzkaller@googlegroups.com \
    --cc=vladimir.oltean@nxp.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®