From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-oi1-f177.google.com (mail-oi1-f177.google.com [209.85.167.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6F8FF38A704 for ; Tue, 10 Mar 2026 11:49:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.177 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773143374; cv=none; b=AoHKXmSXCWLYBRMFRgBZzorj/TK4FeY/6qNkEC2GPWdlpCZnds8fcyqX92KV1BZbbvLiKc3LHyjvYV94IkWozoy4QDEbsIkEivYDEg6aUMVf2b2KJL1aqd4U56uD5QvWH1CvdNt+aEe9on1L9QsuemiO2ntpRo4EXucVDJDDYh4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773143374; c=relaxed/simple; bh=Zr3qcMn4OLx1slxxG1q/v6XHjn/W58Jij9qVOShgcro=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=TjbURedlWcN+9mjW4gQUsru1NjVWXX/JEHuk5SzNCfIzMdWuiAUWVsQ7Z4QSmUPa+H9R7SySj+1sb8YpZ649/W8ZB/fH85hpjK6bPiLPMf6gEJsYZuMpHEBYkJkHzmR6MrlMu1a4yqEnwOH7/xgw1BHdSFry7MWLwg8XzTVwLRw= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=blackwall.org; spf=none smtp.mailfrom=blackwall.org; dkim=pass (2048-bit key) header.d=blackwall.org header.i=@blackwall.org header.b=PXjZhYpl; arc=none smtp.client-ip=209.85.167.177 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=blackwall.org Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=blackwall.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=blackwall.org header.i=@blackwall.org header.b="PXjZhYpl" Received: by mail-oi1-f177.google.com with SMTP id 5614622812f47-467161c4b89so926076b6e.3 for ; Tue, 10 Mar 2026 04:49:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=blackwall.org; s=google; t=1773143372; x=1773748172; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=eRz2iGuRS5c9gUYKqTban2ycHL3n1P/vxXJWakDhtNM=; b=PXjZhYpl/0RcIXC8chJ7scSvE5Gc0t9PMWcQuLETEA9mAUo997liJ6mkRtJLM98kvK zktcoxY40FQk0tM4to7SERn5YNKhzzaYvNr30l2pBagYy1rYJA29gdPO4UnLUgIzOKQQ gOWObrNLkUTL22syetszXwubcqcbJawC8B4XVal9HvVBQNcdVdChOunuk/AJXe2JstAy aT7sbbbSKuJbqZblzgLp/4ACm73zNfcr0OBJPfDOlTgLPkWmykXksuk74zdVSyafdiFb CcK7on7sPZ+TlthhdaWuXy/c2pH1Leuchq29jfh5IvzgB0rFWEidDmxXoiDG96KGtbZJ 9KaQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1773143372; x=1773748172; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-gg:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=eRz2iGuRS5c9gUYKqTban2ycHL3n1P/vxXJWakDhtNM=; b=MKlXR0J4iw0PHJKmqXOLiht4Oe9J7FkmGAsxR1Uc4mXBLLb5UR4fGftSpbtFmH5z7W XL1laAuwPcCYmlLqBiFv95jfWI1oWh2+b2ymohmQlqJ7YWe7d/SvgN0pvrlEX+uIaMSh bNojBO7qRp6Y4S6cDubdTHI2hGaF1LuIKWY0IHZQv9ySK9UBvYe7wB3/Ol3oUJq9Jxui EUDU3BpzZStBRAFGWqh43v4aXY5Fp69iPP6rxJxwzqRAE1Wc2S6pgUGxIjqvfoTkQ2Q4 HUAM8A+4uWF8YKs03TiR950OIOUGO1Bw7w1qjFO7445DjJdm2vhHXbnqUZSg4tc5FUUX Roog== X-Forwarded-Encrypted: i=1; AJvYcCXT4orU0eZK2zPeLbjnq+cVnmTDlVVtFI7wpZv08U5iZ0U7348NdJ8jIba7y7wgzGV3op4HWDgAQf0en6M=@vger.kernel.org X-Gm-Message-State: AOJu0YxGECisVIahRO9FsbU0EHNfjvJ22xswMf9sAmOnCuKtho6MwBza C4bG6HFMuTAcrvAyKtw7LLEZTPNMqoj5HGui/Rj2ev6OwRoDNO7SVrc9FvNtFSG4WwE= X-Gm-Gg: ATEYQzyL9aI3m1GRPcjan/Kw+3DwQwqebRjgtGg+tAhozJdo3PHz68hQbbAzJH0mkvs 3+b0CO4mfCZF345IhoRBtP7GwYuToj+BLYhyuVwXTRjY8mHN3HvWq/X6qnbcCwPHkm4+ywxdUdk NCpmsYA20UeCANzC6ZkNyge2SXHrw3uNbxIpbTIQyzxdosEFlAG1St2jEAq3Y5P3SWzY4zCWaiQ sJp0bJjG+nR+wN3tF/8RcoO/K67VOeUDKsUDkTje+4bQY+OWsiqJFU8YYl+F2dPTjNdTAQXD5FX AbhruhsOydw1B1OzyNO0tEpn+p4Fc89XwFjjyc2+Y4Kip+rUmsVjiUoawxZ4VRCDwyXliMFyayI 9iUCf1Fq8diYaj6S8IV+R38gQXNpCq9vNkkx3LdOGpU/OW7hO3YKFlk1t8XMO7o0BLUjLsg0A4o BgJNNJCivp5PqqnxBF1rtZ X-Received: by 2002:a05:6808:171a:b0:45c:a040:e53c with SMTP id 5614622812f47-466dcb1c40cmr7605844b6e.32.1773143372180; Tue, 10 Mar 2026 04:49:32 -0700 (PDT) Received: from localhost ([216.228.127.131]) by smtp.gmail.com with ESMTPSA id 5614622812f47-466dfac3472sm7496849b6e.15.2026.03.10.04.49.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Mar 2026 04:49:30 -0700 (PDT) Date: Tue, 10 Mar 2026 13:49:25 +0200 From: Nikolay Aleksandrov To: Jiayuan Chen Cc: netdev@vger.kernel.org, jiayuan.chen@shopee.com, syzbot+80e046b8da2820b6ba73@syzkaller.appspotmail.com, Jay Vosburgh , Andrew Lunn , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Alexei Starovoitov , Daniel Borkmann , Jesper Dangaard Brouer , John Fastabend , Stanislav Fomichev , Andrii Nakryiko , Martin KaFai Lau , Eduard Zingerman , Song Liu , Yonghong Song , KP Singh , Hao Luo , Jiri Olsa , Shuah Khan , Sebastian Andrzej Siewior , Clark Williams , Steven Rostedt , Jussi Maki , linux-kernel@vger.kernel.org, bpf@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-rt-devel@lists.linux.dev Subject: Re: [PATCH net v5 1/2] bonding: fix null-ptr-deref in bond_rr_gen_slave_id() Message-ID: References: <20260309030702.128520-1-jiayuan.chen@linux.dev> <20260309030702.128520-2-jiayuan.chen@linux.dev> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20260309030702.128520-2-jiayuan.chen@linux.dev> On Mon, Mar 09, 2026 at 11:06:58AM +0800, Jiayuan Chen wrote: > From: Jiayuan Chen > > bond_rr_gen_slave_id() dereferences bond->rr_tx_counter without a NULL > check. rr_tx_counter is a per-CPU counter only allocated in bond_open() > when the bond mode is round-robin. If the bond device was never brought > up, rr_tx_counter remains NULL, causing a null-ptr-deref. > > The XDP redirect path can reach this code even when the bond is not up: > bpf_master_redirect_enabled_key is a global static key, so when any bond > device has native XDP attached, the XDP_TX -> xdp_master_redirect() > interception is enabled for all bond slaves system-wide. This allows the > path xdp_master_redirect() -> bond_xdp_get_xmit_slave() -> > bond_xdp_xmit_roundrobin_slave_get() -> bond_rr_gen_slave_id() to be > reached on a bond that was never opened. > > Fix this by adding a NULL check with unlikely() in bond_rr_gen_slave_id() > before dereferencing rr_tx_counter. When rr_tx_counter is NULL (bond was > never opened), fall back to get_random_u32() for slave selection. The > allocation in bond_open() is kept, with WRITE_ONCE() added to safely > publish the pointer to the XDP read side. A plain read suffices for the > !bond->rr_tx_counter guard in bond_open() itself, as bond_open() runs > under RTNL lock and is the only writer of rr_tx_counter. > > Fixes: 879af96ffd72 ("net, core: Add support for XDP redirection to slave device") > Reported-by: syzbot+80e046b8da2820b6ba73@syzkaller.appspotmail.com > Closes: https://lore.kernel.org/all/698f84c6.a70a0220.2c38d7.00cc.GAE@google.com/T/ > Signed-off-by: Jiayuan Chen > --- > drivers/net/bonding/bond_main.c | 9 +++++++-- > 1 file changed, 7 insertions(+), 2 deletions(-) > This is Jay's patch + the unlikely change, looks good to me. Reviewed-by: Nikolay Aleksandrov Cheers, Nik > diff --git a/drivers/net/bonding/bond_main.c b/drivers/net/bonding/bond_main.c > index 444519078da3..b8ec87625ce3 100644 > --- a/drivers/net/bonding/bond_main.c > +++ b/drivers/net/bonding/bond_main.c > @@ -4290,9 +4290,11 @@ static int bond_open(struct net_device *bond_dev) > struct slave *slave; > > if (BOND_MODE(bond) == BOND_MODE_ROUNDROBIN && !bond->rr_tx_counter) { > - bond->rr_tx_counter = alloc_percpu(u32); > - if (!bond->rr_tx_counter) > + u32 __percpu *rr_tx_tmp = alloc_percpu(u32); > + > + if (!rr_tx_tmp) > return -ENOMEM; > + WRITE_ONCE(bond->rr_tx_counter, rr_tx_tmp); > } > > /* reset slave->backup and slave->inactive */ > @@ -4883,6 +4885,9 @@ static u32 bond_rr_gen_slave_id(struct bonding *bond) > struct reciprocal_value reciprocal_packets_per_slave; > int packets_per_slave = bond->params.packets_per_slave; > > + if (unlikely(!READ_ONCE(bond->rr_tx_counter))) > + return get_random_u32(); > + > switch (packets_per_slave) { > case 0: > slave_id = get_random_u32(); > -- > 2.43.0 >