From nobody Fri Dec 19 15:00:23 2025 Received: from mail-lf1-f44.google.com (mail-lf1-f44.google.com [209.85.167.44]) (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 5573C33290E for ; Fri, 5 Dec 2025 16:12:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.44 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764951153; cv=none; b=hTDN19oUxXgSDh79pdhoGWTxHJwmdXVyU2N1z77MqGzXG8Uh+1tqs6jQ8d2lF/2WzLvNl559TYOSqlXXTDN/4ekm3+rGbdcl6XoZ7/uuZOqLKOsxzzpmiw/V6qUGVDsWHa4127CCF1sWtZSNnr7Seu2aclRv/PrOon4VoctgaQ8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764951153; c=relaxed/simple; bh=+Uij/c+hhRUh7KNHXiyStM+eLLPbLJJe16gbEXkk+T0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=sml5WvXzT2IW2EnP59B3WAJArDlbhLsoFrXvzpNvLZHn1TUHCBqxICwVXTthXenJcD+PIv7EXvcT5oWHsM/cuxRYGgDJYr/FNlyZ1RBxXUyZK6wQiI/diPRU53EEyc9Xx7wRT2pAVTnj6fud9AqsoUnEHZRkUDt3DflDKUEa5Iw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=IkYB7uSh; arc=none smtp.client-ip=209.85.167.44 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="IkYB7uSh" Received: by mail-lf1-f44.google.com with SMTP id 2adb3069b0e04-5958187fa55so1825747e87.3 for ; Fri, 05 Dec 2025 08:12:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1764951146; x=1765555946; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=yRu3vn/L5SRaR0SSwrxKoGLCPSzcYT0aQdaJ5FnQFyM=; b=IkYB7uShocAhmJ7P5qSUjQiXXB5V/BjB5XNHNdEd4ViMoYfPtXkeZznACaGotyTCPd fEo3I9f4SGuxLOI40RPCDf0Tvo0loW2XgT3scDlD6zo+r17OqrnUfVdZNwnrG1sd+w+b F64hcHCLfSjyQT+03ealjZj4fhYOxd1UF9iR09nhozM9lWSn3kjTP3Bppxixz5TpaZ47 oF9XsclvOreCr6pSZEO+OKFOemO3ntu+HTm+7UFFTqDUm4qzQRrwILOOHan/oCs6LfYD IBtGr6phoV83IHD1xvgngCF/tdDLWw89bn38MnBw0NaWVE6XaUxfn2AZx8+g2q/wvUvG SrKw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1764951146; x=1765555946; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=yRu3vn/L5SRaR0SSwrxKoGLCPSzcYT0aQdaJ5FnQFyM=; b=kjF57OJOlGDvsfTE6i7WKjQVWEri6QhSJ/jneBOwu51L+iDW7/bQL0u2uVk899rsHU ommvomyGy+UpTectEP9z1wqCc8vtmYSTJlZ0sTe0CtpUDw8EMJXh5OMSSUCn7USXU8k3 F1sZe7smGL5FxiHj/V/m67cLTQsDA4efypmb+KGeINKEG1OxqP1rcI4VVMkLHYSCCvs7 9VRU0YH9r5nQjaqDEG78rjNkSjUVKWMoBrpNHduNZxZ/GGVDzyiLatroDOVP2xbrAVx5 H2nr3xowrJWTQqfa1u4vnhuE7ORYyOP/PoaZJqGwBoRPkA8JlexO8CARXKlNcZa8aN/a V+Iw== X-Forwarded-Encrypted: i=1; AJvYcCVMcrZWX+BGhO+J9G3v1sXq2GHMmzwTfGYc69oTKvJafKiBx/jf+DcHa8Xb9UB4ugbBepk481gVEihplwM=@vger.kernel.org X-Gm-Message-State: AOJu0YwOT1TB8a8lbzDn6cf1FkA+j8jwSE0LLgwt+Zpv8Yur7YbtSwc0 QhoE6bG3eMAhCAhv8L+YeSwLe0YifIo15ewUoAsA2u/1hxBKocsvuLpn X-Gm-Gg: ASbGncsD8fE0vyq0a2HLJWMtpL5bVVlPUq6Wz3PFWmG7oiz7Co5VJG06YUdlE56braf tgftsA0BB0huPbi2tVPctIbW5rprkbcDkV9rYbbm0SnYCzZ2JqL87IOaPXIX3ZoiSzkyKtMMMzo 9CBGuSzFPmeE1S9Tb91DBL+Kjx4AIdyq0msgf+B12iSaa02qvqQfuEAj7lmBKU+tlKXq08MdpZY bcS4K541vu2M3M8b8WMnFlKh4aET1NbWSqWHX7OplzzQXuT0saRQ1M44vlOd8I4e/FVuFZXZPVn lh8r4F29bDbQKO5OH0l+HRb9fjMh7haP+ppIy2oAzo+TbFcuVG4cBbtkE98VgxLo1AUmJs3LV+Z yXdt+51/mNfSHRbqKeBeZgPHDOfcjEiGLFa6KVB5lJAeza8oev2OsznEqbNRwJglvgW59cEylEh /0WfShx6Dp8LXhgD4Pu8agTQ== X-Google-Smtp-Source: AGHT+IFIv8sNT85tAoTM0JCKoOGi4DeHIdsW4Qkp4uPPjvN5cusGwlRPEBYBIrgPH3hNnQEFUHZHvw== X-Received: by 2002:a05:6512:39d2:b0:594:b2be:f3a with SMTP id 2adb3069b0e04-597d66c816amr2685904e87.25.1764951145521; Fri, 05 Dec 2025 08:12:25 -0800 (PST) Received: from localhost ([188.234.148.119]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-597d7b1a920sm1654026e87.12.2025.12.05.08.12.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Dec 2025 08:12:24 -0800 (PST) From: Mikhail Gavrilov To: Mario Limonciello Cc: Felix Fietkau , Lorenzo Bianconi , linux-wireless@vger.kernel.org, linux-mediatek@lists.infradead.org, linux-kernel@vger.kernel.org, Mikhail Gavrilov Subject: [PATCH v2] wifi: mt76: Fix strscpy buffer overflow in mt76_connac2_load_patch Date: Fri, 5 Dec 2025 21:12:02 +0500 Message-ID: <20251205161202.48409-1-mikhail.v.gavrilov@gmail.com> X-Mailer: git-send-email 2.52.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Commit f804a5895eba ("wifi: mt76: Strip whitespace from build ddate") intro= duced a kernel panic/WARN on systems using MediaTek MT7921e (and potentially othe= rs using mt76_connac_lib) due to an incorrect buffer size calculation. The error logged is: "strnlen: detected buffer overflow: 17 byte read of buffer size 16" This occurs because the field 'hdr->build_date' is a fixed-size array of 16= bytes. The patch allocated a 17-byte local buffer 'build_date' but used 'sizeof(bu= ild_date)' (17) as the read limit for strscpy, causing Fortify Source to correctly det= ect an attempt to read 17 bytes from the 16-byte source field. To fix this, replace strscpy with memcpy, which is appropriate for raw data copying, and explicitly use the size of the source field (sizeof(hdr->build= _date) =3D 16) to limit the read, followed by manual null termination. Fixes: f804a5895eba ("wifi: mt76: Strip whitespace from build ddate") Signed-off-by: Mikhail Gavrilov Reviewed-by: Mario Limonciello (AMD) Tested-by: Eric Biggers Tested-by: Mario Limonciello (AMD) --- drivers/net/wireless/mediatek/mt76/mt76_connac_mcu.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/drivers/net/wireless/mediatek/mt76/mt76_connac_mcu.c b/drivers= /net/wireless/mediatek/mt76/mt76_connac_mcu.c index ea99167765b0..d2c4c65ec464 100644 --- a/drivers/net/wireless/mediatek/mt76/mt76_connac_mcu.c +++ b/drivers/net/wireless/mediatek/mt76/mt76_connac_mcu.c @@ -3125,8 +3125,11 @@ int mt76_connac2_load_patch(struct mt76_dev *dev, co= nst char *fw_name) } =20 hdr =3D (const void *)fw->data; - strscpy(build_date, hdr->build_date, sizeof(build_date)); - build_date[16] =3D '\0'; + /* hdr->build_date is 16 bytes. Copy exactly 16 bytes to the 17-byte buff= er, + * and then add the null terminator at index 16. + */ + memcpy(build_date, hdr->build_date, sizeof(hdr->build_date)); + build_date[sizeof(hdr->build_date)] =3D '\0'; strim(build_date); dev_info(dev->dev, "HW/SW Version: 0x%x, Build Time: %.16s\n", be32_to_cpu(hdr->hw_sw_ver), build_date); --=20 2.52.0