From: Edward Adam Davis eadavis@qq.com
[ Upstream commit c575f5374be7a5c4be4acb9fe6be3a4669d94674 ]
Setting tsf is meaningless if beacon is disabled, so check that beacon is enabled before setting tsf.
Reported-by: syzbot+064815c6cd721082a52a@syzkaller.appspotmail.com Closes: https://syzkaller.appspot.com/bug?extid=064815c6cd721082a52a Tested-by: syzbot+064815c6cd721082a52a@syzkaller.appspotmail.com Signed-off-by: Edward Adam Davis eadavis@qq.com Link: https://patch.msgid.link/tencent_3609AC2EFAAED68CA5A7E3C6D212D1C67806@qq.com Signed-off-by: Johannes Berg johannes.berg@intel.com Signed-off-by: Sasha Levin sashal@kernel.org ---
Perfect! Now I can see the exact issue. The function uses `do_div(delta, bcn_int)` where `bcn_int` comes from `data->link_data[0].beacon_int`. When beacons are disabled, this value could be 0, leading to a division by zero error. **YES** This commit should be backported to stable kernel trees. Here's my extensive analysis: ## Analysis of the Commit ### The Bug The commit fixes a **division by zero vulnerability** in the `mac80211_hwsim_set_tsf()` function. The issue occurs when: 1. **Beacons are disabled** (`enable_beacon = false`) 2. **Beacon interval becomes 0** (as seen in line 2569: `link_data->beacon_int = 0;`) 3. **TSF is still being set**, leading to `do_div(delta, bcn_int)` operations where `bcn_int = 0` ### Code Analysis The problematic code was: ```c u32 bcn_int = data->link_data[0].beacon_int; // Could be 0 when beacons disabled u64 delta = abs(tsf - now); // ... data->bcn_delta = do_div(delta, bcn_int); // Division by zero! ``` The fix adds a safety check: ```c conf = link_conf_dereference_protected(vif, data->link_data[0].link_id); if (conf && !conf->enable_beacon) return; // Exit early when beacons are disabled ``` ### Why This Should Be Backported 1. **Critical Bug Fix**: This fixes a **division by zero kernel bug** that could cause kernel panics or crashes. 2. **Security Issue**: The commit references a **syzbot report** (`syzbot+064815c6cd721082a52a@syzkaller.appspotmail.com`), indicating this is a reproducible security issue found by automated fuzzing. 3. **Small and Contained**: The fix is minimal - just 5 lines of code that add a safety check. It follows the stable tree rule of being a small, targeted fix. 4. **No Architectural Changes**: This doesn't introduce new features or make architectural changes. It simply prevents an invalid operation from occurring. 5. **Low Regression Risk**: The fix is defensive programming - it only prevents the function from executing when beacons are disabled, which makes logical sense since TSF adjustment is meaningless without beacons. 6. **Driver-Specific**: This affects the `mac80211_hwsim` virtual driver, which is commonly used for testing and virtualization, making the fix important for testing infrastructure. 7. **Logical Fix**: The commit message clearly states "Setting tsf is meaningless if beacon is disabled" - this is a logical improvement that prevents undefined behavior. ### Backport Suitability - ✅ **Bug fix**: Yes, fixes division by zero - ✅ **Small change**: Only 5 lines added - ✅ **Contained**: Limited to one function in one driver - ✅ **Low risk**: Defensive check, cannot cause regressions - ✅ **Security relevant**: Prevents kernel crashes - ✅ **Clear benefit**: Prevents undefined behavior This is exactly the type of commit that stable trees are designed for - a small, targeted fix for a real bug that affects system stability.
drivers/net/wireless/virtual/mac80211_hwsim.c | 5 +++++ 1 file changed, 5 insertions(+)
diff --git a/drivers/net/wireless/virtual/mac80211_hwsim.c b/drivers/net/wireless/virtual/mac80211_hwsim.c index a68530344d205..52d480fa7227a 100644 --- a/drivers/net/wireless/virtual/mac80211_hwsim.c +++ b/drivers/net/wireless/virtual/mac80211_hwsim.c @@ -1229,6 +1229,11 @@ static void mac80211_hwsim_set_tsf(struct ieee80211_hw *hw, /* MLD not supported here */ u32 bcn_int = data->link_data[0].beacon_int; u64 delta = abs(tsf - now); + struct ieee80211_bss_conf *conf; + + conf = link_conf_dereference_protected(vif, data->link_data[0].link_id); + if (conf && !conf->enable_beacon) + return;
/* adjust after beaconing with new timestamp at old TBTT */ if (tsf > now) {