fix: backport upstream Wi-Fi bounds and build failure handling

This commit is contained in:
kanoqwq committed 2026-10-18 18:45:10 +08:00
1 parent 99e1316a7c
commit c21b00452c
9 files changed
+235 -6

No files matched your search

+43
View File
@@ -0,0 +1,43 @@
# 上游变更筛选与适配(2026-10-18)
## 范围
- E5 上游:[main 5ac9d504](https://github.com/sprd-linux-devs/e5-linux/commit/5ac9d504c984d47c46378c0373a1c49909e66e8d)。该分支发生过强制更新,采用设备/公共组件拆分布局。
- MU300 上游:[main 2c06845c](https://github.com/dikeckaan/mu300-linux/commit/2c06845c11da6e76653558566d3a74f4929e4ed1)。相对上次审查记录的 2c13e7bb,有 141 条非合并提交;先按标题和修改路径筛选,再逐行审查本次采用的补丁。
- 这不是全部历史/全部新代码的安全审计,也没有整分支合并。MU300 继续维护 `clean-tf-7.2`,未改另一工作树的 main,未向任何远端推送。
## 本次补入
| 来源 | 适配结果 |
| --- | --- |
| E5 [720e21c3](https://github.com/sprd-linux-devs/e5-linux/commit/720e21c35254e1739a92869ffae0fa44af1e8761) | 两个 kernel build 入口在输出目录运行 merge_config,避免在源码目录创建临时文件;本地 native 输出目录额外转为绝对路径,兼容用户传相对路径。保留现有共享硬件适配器。 |
| E5 [053bd469](https://github.com/sprd-linux-devs/e5-linux/commit/053bd469) | hostapd 容器使用宿主架构,空缓存先构建 host tools/toolchain。E5 的 BlueZ 同用一个构建卷,原先硬编码 ARM64,故也统一架构。MU300 的同源 hostapd 构建脚本同步。未知架构明确报错。 |
| E5 [5ac9d504](https://github.com/sprd-linux-devs/e5-linux/commit/5ac9d504c984d47c46378c0373a1c49909e66e8d) | E5 bootctl 以打包用户 UID/GID 编译,并提前检查文件归属,避免非 root 打包时 chmod 失败。其他机型的 Python 构建入口本来就在宿主编译,不额外套容器。 |
| MU300 [b5a7bc55](https://github.com/dikeckaan/mu300-linux/commit/b5a7bc55cab8bd62ff14dbba93e11c8120bc6133) / PR #282 | AP 未给 mgmt_tx 信道时使用自身有效信道,拒绝无信道的 off-channel/非 AP/MLO 请求;station 加入/离开事件先校验实际缓冲区长度,按小端解析 IE 长度并检查上界。保留本地 SAE/发送修复。E5 接入公共适配器,E5/T551M/M8 和 upstream 两种构建入口都经现有 wifi-stations 入口调用,幂等、不依赖开启 SAE。 |
| MU300 [be60c552](https://github.com/dikeckaan/mu300-linux/commit/be60c5524d85d6d4fc7f95214403aa6758adfa21) / PR #321 | 两个旧 vendor kernel 构建辅助脚本保留 make 的退出码,不能因 grep/tail 成功而误报构建成功、收集旧模块。仅修脚本错误传播,不开启或编译 5.4 发布版本。现有 mainline build 入口已有 pipefail。 |
以上没有新运行时服务、额外正常启动 AT、SFUN、启动等待、无线参数默认值或充电/电量算法变更。
## 跳过或保留待单独评估
- **已有本地对应实现**:HS400 初始化失败降级(5558eef5)、U30 电量保存(6a084453)、无卡事件、射频禁用/VoLTE/VoNR 回放、U30 灯、AP station 数据、ICCID/APN、独立分区发现及 ext4 检查。不能用上游较早实现覆盖本地后续修复;尤其电量保存不能恢复已纠正的 force-write 行为。
- **E5 布局与内核源码迁移**:68593473、735f169d、72f4ac4a 将本地修复重新落到拆分组件并改变 CI/source baseline。需要整套组件与发布工作流迁移,不能把 gitlink、旧版本号设置和本地模型配置直接混合。没有直接导入或删除本地构建时驱动适配。
- **E5 CI/QEMU/缓存和 macOS 大小写说明**:0d0bfc15、2f34516a 主要面向拆分后的 release 仓库。macOS 平铺 `xt_RATEEST.ko`/`xt_rateest.ko` 的风险值得保留,但文档里“不是构建错误”不能当作忽略模块覆盖的理由。本次没有放宽模块校验。
- **MU300 大型音频/Cockpit 栈**:e893ec58、6e30d08a 等涉及大量新驱动和用户空间,不适合作为简单补丁替换现有 E5 已验证通话路径;没有向无屏设备强制加入新面板/通话栈。
- **MU300 lossless/delta 更新**:用户已取消增量更新功能;不引入另一套增量、硬链接、模块回滚和包恢复实现。0c3cefa5 所修的可选参数函数在本地旧布局更新器中不存在,不凭名称套补丁。
- **MU300 android-run UID 统一(0c63d0a4)**:依赖上游此前的专用用户隔离架构。本地仍由 vendor daemon 自身切 UID,不存在该提交描述的“节点归专用用户、daemon 仍为 1000”组合,不增加未适配的 setpriv 路径。
- **MU300 温控趋势算法(4c47e53e)**:涉及新的采样历史、斜率、释放阈值和降频节奏;不是机械修正。没有当前各板原厂对照证据,按硬件修复原则暂不采用上游新增的数值策略。
- **MU300 SIPA/WCN 降噪(6d2796e6)**:本地有既有错误分类、重试与限频实现;上游同时调整若干错误分支日志和 logd 容量,需独立区分正常频繁日志与真实传输失败,不能整体覆盖本地发送路径或一概压成 debug。
- **MU300 U30 禁用 SAE(29b4c81a)**:用户已明确要求找到可信密钥通道前不改变该功能,本次不改认证策略,也不声称固件密钥来源疑问已解决。
- **MU300 zram、extras、下载镜像/备份、SMS 隐私路径**:是独立功能/架构修改;本次未照搬。SMS stdin/权限加固涉及发送者、编码器和转发目录的联动,不能仅取一部分声称完成。
- **内核升级与默认模块扩充**:保留当前 6.18.54/7.2.8 及模型配置,不预装 Docker、VPN,不增大现有发布包。上游 #299 也吸收了我方部分 Wi-Fi/电量修复,不能再次当成全新补丁叠加。
## 验证与实际限制
- E5:实际执行构建脚本的架构选择/容器参数片段,模拟 x86_64/aarch64/arm64;校验空缓存补建顺序、已有工具不重复构建、带空格源码/输出路径的 merge cwd 和 bootctl 所有者参数。
- E5 原有 hybrid-package 8 项测试通过;相关 shell 语法检查通过。
- 两仓库:抽取实际 station callback 和信道检查编译运行 C 测试,覆盖截断事件、短 leave、过长 IE、合法空 IE、AP/P2P、自身信道缺失、off-channel 和 MLO 拒绝。
- E5:公共适配器在本地实际 E5 内核源码副本上重复应用成功。所有模型现有入口共用 wifi-stations,不新增独立分支实现。
- MU300:改动后的 cfg80211/cmdevt 对象分别按真实 6.18.54 和 7.2.8 内核配置交叉编译通过;只编译对象,未替换现有发布模块/镜像。
- MU300:上游构建错误传播测试 2 项通过,包含真实 shell 下 mock make 失败/成功退出码。
- 本次未热部署、未刷机、未重打包,未做新的 Wi-Fi/低电量实机验证。现有 ZIP 不会因源码修改自动更新。
+5 -1
View File
@@ -25,7 +25,11 @@ open('/work/fragment-rejected.txt','w').write('\n'.join(bad)+'\n'); print('fragm
P
cp $OUT/.config /work/linux.config
start=$(date +%s)
$M Image modules 2>&1 | grep -E "error|Error|warning: unused|LTO|^make" | tail -40
# the log is filtered, but make's own status decides: a module that fails to compile must fail the build, not leave
# the previous build's .ko in place to be collected as if it were new
$M Image modules > /work/build.log 2>&1 || status=$?
grep -E "error|Error|warning: unused|LTO|^make" /work/build.log | tail -40 || true
[ -z "${status:-}" ] || { echo "kernel build failed (make exit $status)"; exit "$status"; }
echo "BUILD_SECONDS $(( $(date +%s) - start ))"
ls -la $OUT/arch/arm64/boot/Image
find $OUT -name "*.ko" | wc -l
+3 -1
View File
@@ -26,7 +26,9 @@ print('u30air fragment rejected:', len(bad)); [print(' '+b) for b in bad]
P
# no module of an earlier build may linger (one the fragment no longer builds would be taken for a U30 Air module)
find $OUT -name '*.ko' -delete
$M Image modules 2>&1 | grep -E "error|Error" | tail -20 || true
$M Image modules > /work/build-u30air.log 2>&1 || status=$?
grep -E "error|Error" /work/build-u30air.log | tail -20 || true
[ -z "${status:-}" ] || { echo "U30 Air kernel build failed (make exit $status)"; exit "$status"; }
# the Image must be the MU300 one: a fragment option that changes built-in code shows up as a different set of
# symbols vmlinux exports to modules (I2C_SMBUS did: of_i2c_setup_smbus_alert)
cmp -s <(awk '$3=="vmlinux"' $BASE/Module.symvers | sort) <(awk '$3=="vmlinux"' $OUT/Module.symvers | sort) \
+3
View File
@@ -27,6 +27,9 @@ printf '%s\n' 'CONFIG_PACKAGE_wpad-basic-mbedtls=m' 'CONFIG_PACKAGE_hostapd-comm
'CONFIG_PACKAGE_wifi-scripts=m' 'CONFIG_WIFI_SCRIPTS_UCODE=y' \
'CONFIG_SIGNED_PACKAGES=n' >> .config
make defconfig
# A valid package cache need not contain a prepared host toolchain.
ls staging_dir/host/bin/openssl >/dev/null 2>&1 || make -j"${JOBS:-4}" tools/install
ls staging_dir/toolchain-*/bin/*-gcc >/dev/null 2>&1 || make -j"${JOBS:-4}" toolchain/install
# Out-of-tree Unisoc modules do not select OpenWrt kmod-mac80211 options.
# Preserve the official daemon's AC/AX/BE config parser and PHY support.
hostapd_make() {
+4 -2
View File
@@ -20,9 +20,11 @@ if [ -s "$OUT/build-id" ] && [ "$(cat "$OUT/build-id")" = "$stamp" ] &&
echo 'Unisoc WPA3: verified APK cache'
exit 0
fi
docker build --platform linux/amd64 -t unisoc-hostapd-build \
# Share the buildroot's host architecture with ModemManager and BlueZ.
case "$(uname -m)" in x86_64) PLAT=linux/amd64;; aarch64|arm64) PLAT=linux/arm64;; *) echo 'Unsupported build host architecture' >&2; exit 1;; esac
docker build --platform "$PLAT" -t unisoc-hostapd-build \
-f "$TOP/openwrt/hostapd.Dockerfile" "$TOP/openwrt"
docker run --rm --platform linux/amd64 \
docker run --rm --platform "$PLAT" \
-v "${UNISOC_WRT_CACHE:-e5-openwrt-src}:/build" \
-v "$TOP/openwrt:/src:ro" -v "$OUT:/out" \
-e "VER=$VER" -e "BUILD_ID=$stamp" -e "JOBS=${UNISOC_JOBS:-4}" \
+99
View File
@@ -0,0 +1,99 @@
#!/usr/bin/env python3
"""Compile the real event callback/channel checks; no wireless hardware needed."""
from pathlib import Path
import runpy
import subprocess
import tempfile
TOP = Path(__file__).resolve().parents[2]
def function(text, name):
start = text.index(name + '(')
brace = text.index('{', start)
depth = 1
end = brace + 1
while depth:
depth += (text[end] == '{') - (text[end] == '}')
end += 1
return text[brace + 1:end - 1]
with tempfile.TemporaryDirectory() as tmp:
tmp = Path(tmp)
adapter = TOP / 'devices/common/wifi-events.py'
if adapter.exists():
base = tmp / 'drivers/unisoc_platform/sprd_wlan_combo'
(base / 'common').mkdir(parents=True)
(base / 'sc2355').mkdir()
(base / 'common/cfg80211.c').write_text('''int sprd_cfg80211_mgmt_tx(void) {
struct ieee80211_channel *chan = params->chan;
\t*cookie = ++mgmt_index;
}''')
(base / 'sc2355/cmdevt.c').write_text('''void cmdevt_report_new_station_evt(void) {
struct evt_new_station *sta = (struct evt_new_station *)data;
\tsprd_report_softap(vif, sta->is_connect, sta->mac, sta->ie,
\t\t\t sta->ie_len);
}''')
apply = runpy.run_path(str(adapter))['apply']
apply(tmp)
before = {p: p.read_bytes() for p in base.rglob('*.c')}
apply(tmp)
assert all(p.read_bytes() == data for p, data in before.items())
else:
base = TOP / 'upstream/modules/sprd_wlan_combo'
event = function((base / 'sc2355/cmdevt.c').read_text(), 'cmdevt_report_new_station_evt')
mgmt = function((base / 'common/cfg80211.c').read_text(), 'sprd_cfg80211_mgmt_tx')
# Exercise exactly the pre-cookie checks, without mocking the transmit path.
checks = mgmt[mgmt.index('if (!chan)'):mgmt.index('*cookie = ++mgmt_index;')]
code = r'''
#include <stdint.h>
#include <stdbool.h>
#include <assert.h>
#include <errno.h>
#include <stddef.h>
typedef uint8_t u8;
typedef uint16_t u16;
#define KERNEL_VERSION(a,b,c) (((a)<<16)|((b)<<8)|(c))
#define LINUX_VERSION_CODE KERNEL_VERSION(6,18,54)
#define NL80211_IFTYPE_AP 1
#define NL80211_IFTYPE_P2P_GO 2
#define le16_to_cpu(x) (x)
struct sprd_vif { int unused; };
struct evt_new_station { u8 is_connect, mac[6]; u16 ie_len; u8 ie[]; } __attribute__((packed));
static int calls, last_len;
static void sprd_report_softap(struct sprd_vif *v, int connected, u8 *mac, u8 *ies, int len)
{ (void)v; (void)connected; (void)mac; (void)ies; calls++; last_len = len; }
static void event(struct sprd_vif *vif, u8 *data, u16 len) { EVENT }
struct ieee80211_channel { int freq; };
struct wireless_dev { int iftype, valid_links;
struct { struct { struct { struct ieee80211_channel *chan; } chandef; } ap; } links[1]; };
struct params { bool offchan; int link_id; };
static int channel(struct wireless_dev *wdev, struct params *params, struct ieee80211_channel *chan)
{ CHECKS return chan->freq; }
int main(void) {
unsigned char buf[64] = {0}; struct evt_new_station *s = (void *)buf;
for (int i=0; i<7; i++) { event(NULL, buf, i); assert(calls==0); }
event(NULL,buf,7); assert(calls==1 && last_len==0);
s->is_connect=1;
for(int i=0;i<9;i++) { event(NULL,buf,i); assert(calls==1); }
s->ie_len=65535; event(NULL,buf,64); assert(calls==1);
s->ie_len=56; event(NULL,buf,64); assert(calls==1);
s->ie_len=55; event(NULL,buf,64); assert(calls==2 && last_len==55);
s->ie_len=0; event(NULL,buf,9); assert(calls==3 && last_len==0);
struct ieee80211_channel c = {5180}; struct wireless_dev w = {.iftype=1}; struct params p={0};
assert(channel(&w,&p,NULL)==-ENODATA);
w.links[0].ap.chandef.chan=&c; assert(channel(&w,&p,NULL)==5180);
p.offchan=1; assert(channel(&w,&p,NULL)==-EINVAL); p.offchan=0;
p.link_id=1; assert(channel(&w,&p,NULL)==-EINVAL); p.link_id=0;
w.valid_links=1; assert(channel(&w,&p,NULL)==-EINVAL); w.valid_links=0;
w.iftype=0; assert(channel(&w,&p,NULL)==-EINVAL);
w.iftype=2; assert(channel(&w,&p,NULL)==5180);
assert(channel(&w,&p,&c)==5180);
}
'''.replace('EVENT', event).replace('CHECKS', checks)
cfile = tmp / 'test.c'
cfile.write_text(code)
subprocess.run(['cc', '-Wall', '-Wextra', '-Werror', str(cfile), '-o', str(tmp / 'test')], check=True)
subprocess.run([str(tmp / 'test')], check=True)
print('SC2355 event bounds/channel checks passed (compiled C; no hardware)')
+41
View File
@@ -0,0 +1,41 @@
"""A kernel or module that fails to compile fails kernel/build-all.sh.
build-linux.sh and build-u30air.sh filter make's output through grep and tail; in a pipeline the status was tail's,
so a failed sipa_eth.c still reported success and the previous build's .ko were collected as new. make's status now
decides, and the filtered lines are still printed."""
import subprocess
import tempfile
import unittest
from pathlib import Path
from helpers import TOP
SCRIPTS = ['kernel/build-linux.sh', 'kernel/build-u30air.sh']
class MakeStatus(unittest.TestCase):
def test_no_pipeline_hides_make(self):
for s in SCRIPTS:
text = (TOP / s).read_text()
self.assertNotRegex(text, r'\$M Image modules[^\n|]*\| *(grep|tail)', s)
self.assertIn('$M Image modules > ', text, s)
def test_failed_make_exits_nonzero(self):
# the three lines of build-linux.sh, run with a make that fails
lines = (TOP / 'kernel/build-linux.sh').read_text().splitlines()
i = next(n for n, l in enumerate(lines) if l.startswith('$M Image modules'))
with tempfile.TemporaryDirectory() as d:
body = '\n'.join(lines[i:i + 3]).replace('/work/', d + '/')
for make, want in (('echo "foo.c:1: error: x"; exit 2', 2), ('echo ok', 0)):
fake = Path(d) / 'make'
fake.write_text(make + '\n')
r = subprocess.run(['bash', '-ec', f'M="sh {fake}"\n{body}\necho done'],
capture_output=True, text=True)
self.assertEqual(r.returncode, want, r.stdout + r.stderr)
if want:
self.assertIn('error: x', r.stdout)
self.assertNotIn('done', r.stdout)
if __name__ == '__main__':
unittest.main()
@@ -1200,6 +1200,26 @@ int sprd_cfg80211_mgmt_tx(struct wiphy *wiphy, struct wireless_dev *wdev,
static u64 mgmt_index;
int ret = 0;
/* MU300 (from PR #237, oswaldxdd): nl80211 lets an access point send a management frame on its own channel
* without naming a frequency, and the vendor code dereferenced params->chan regardless (an oops at
* mgmt_tx+0x60). Without a channel: the access point's own, never an off-channel one.
*/
if (!chan) {
if (params->offchan ||
(wdev->iftype != NL80211_IFTYPE_AP && wdev->iftype != NL80211_IFTYPE_P2P_GO))
return -EINVAL;
#if (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 15, 0))
/* one non-MLO link on this chip */
if (wdev->valid_links || params->link_id > 0)
return -EINVAL;
chan = wdev->links[0].ap.chandef.chan;
#else
chan = wdev->chandef.chan;
#endif
if (!chan)
return -ENODATA;
}
*cookie = ++mgmt_index;
netdev_info(wdev->netdev, "%s cookie %lld\n", __func__, *cookie);
@@ -3375,9 +3375,24 @@ static void cmdevt_report_remain_on_channel_evt(struct sprd_vif *vif, u8 *data,
static void cmdevt_report_new_station_evt(struct sprd_vif *vif, u8 *data, u16 len)
{
struct evt_new_station *sta = (struct evt_new_station *)data;
u16 ie_len;
sprd_report_softap(vif, sta->is_connect, sta->mac, sta->ie,
sta->ie_len);
/* MU300 (from PR #237, oswaldxdd): the event's own length bounds what is read. A station that left needs
* only the flag and the address (its ie_len is not used); a new one hands cfg80211 at most the bytes the
* event carries, never what ie_len claims beyond them.
*/
if (len < sizeof(sta->is_connect) + sizeof(sta->mac))
return;
if (!sta->is_connect) {
sprd_report_softap(vif, 0, sta->mac, NULL, 0);
return;
}
if (len < sizeof(*sta))
return;
ie_len = le16_to_cpu(sta->ie_len);
if (ie_len > len - sizeof(*sta))
return;
sprd_report_softap(vif, sta->is_connect, sta->mac, sta->ie, ie_len);
}
/* @flag: 1 for data, 0 for event */