From: Jakub Kicinski <kuba@kernel.org>
To: zhangdandan@uniontech.com
Cc: Jakub Kicinski <kuba@kernel.org>,
syzbot+9db6c624635564ad813c@syzkaller.appspotmail.com,
petkan@nucleusys.com, andrew+netdev@lunn.ch, andrew@lunn.ch,
michal.pecio@gmail.com, netdev@vger.kernel.org,
davem@davemloft.net, linux-kernel@vger.kernel.org,
pabeni@redhat.com, horms@kernel.org, linux-usb@vger.kernel.org,
edumazet@google.com
Subject: Re: [PATCH v2] usb: rtl8150: avoid using uninitialized CSCR value
Date: Thu, 23 Apr 2026 11:42:17 -0700 [thread overview]
Message-ID: <20260423184216.3235637-2-kuba@kernel.org> (raw)
In-Reply-To: <F20002D619544E87+20260421105145.11394-1-zhangdandan@uniontech.com>
This is an AI-generated review of your patch. The human sending this
email has considered the AI review valid, or at least plausible.
For local reproduction steps see https://netdev-ai.bots.linux.dev/ai-local.html
---
usb: rtl8150: avoid using uninitialized CSCR value
This commit fixes an uninitialized variable bug in set_carrier() where
get_registers() could fail, leaving tmp uninitialized. The fix adds a
return value check to bail out on error, preserving the existing carrier
state.
Reported-by: syzbot+9db6c624635564ad813c@syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=9db6c624635564ad813c
Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
> set_carrier() reads CSCR via get_registers() (a USB control transfer)
> without checking the return value, so a transient control transfer
> failure would leave the on-stack "tmp" uninitialized and then be used
> to decide the netif carrier state.
>
> Check the return value of get_registers() and bail out on error,
> leaving the previously known carrier state untouched. A failed USB
> control transfer here may be transient (e.g. EMI, flaky cable, retries
> exhausted), so it is wrong to force the link down on such failures and
> cause the carrier state to toggle unnecessarily.
The commit message says "it is wrong to force the link down on such
failures" - but is this characterization accurate?
The original (pre-patch) code did not deliberately force the link down on
failure. It used an uninitialized value, which would randomly either set
carrier on or off depending on stack contents. The statement reads as if
the original code forced link down, but the original bug was random
behavior from uninitialized data.
The "force the link down" language more accurately describes what the
rejected v1 patch did, and why v2 changed the approach to just returning.
>
> This only addresses the uninitialized-value usage and does not change
> link-state policy.
Is this description fully accurate? The patch does change observable
behavior:
Before: on get_registers() failure, carrier state was set to a random value
(on or off based on stack contents).
After: on failure, carrier state is preserved unchanged.
This is a change from "set carrier based on garbage data" to "preserve
previous carrier state." While "using uninitialized data" was never an
intentional policy, the commit does introduce a new explicit behavior
(early return preserving state) that did not exist before.
Additionally, set_carrier() is only called from rtl8150_open() in this
driver, meaning the "previously known carrier state" at that point is the
default state from alloc_etherdev (carrier ON, since __LINK_STATE_NOCARRIER
bit is 0 in zero-initialized memory). On first open, a get_registers()
failure would preserve carrier=ON, which could report link up when the
register read failed.
> diff --git a/drivers/net/usb/rtl8150.c b/drivers/net/usb/rtl8150.c
> index 4cda0643afb6..76962dcd127d 100644
> --- a/drivers/net/usb/rtl8150.c
> +++ b/drivers/net/usb/rtl8150.c
> @@ -722,7 +722,8 @@ static void set_carrier(struct net_device *netdev)
> rtl8150_t *dev = netdev_priv(netdev);
> short tmp;
>
> - get_registers(dev, CSCR, 2, &tmp);
> + if (get_registers(dev, CSCR, 2, &tmp) < 0)
> + return;
> if (tmp & CSCR_LINK_STATUS)
> netif_carrier_on(netdev);
> else
--
pw-bot: cr
prev parent reply other threads:[~2026-04-23 18:42 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-02 7:07 [PATCH] usb: rtl8150: avoid using uninitialized CSCR value Morduan Zang
2026-04-02 15:51 ` Petko Manolov
2026-04-03 15:45 ` Simon Horman
2026-04-05 8:52 ` Petko Manolov
2026-04-05 23:38 ` Andrew Lunn
2026-04-08 8:33 ` Michal Pecio
2026-04-08 12:26 ` Andrew Lunn
2026-04-08 8:18 ` Morduan Zang
2026-04-21 10:51 ` [PATCH v2] " Morduan Zang
2026-04-23 18:42 ` Jakub Kicinski [this message]
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=20260423184216.3235637-2-kuba@kernel.org \
--to=kuba@kernel.org \
--cc=andrew+netdev@lunn.ch \
--cc=andrew@lunn.ch \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=horms@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-usb@vger.kernel.org \
--cc=michal.pecio@gmail.com \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=petkan@nucleusys.com \
--cc=syzbot+9db6c624635564ad813c@syzkaller.appspotmail.com \
--cc=zhangdandan@uniontech.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