Received: by 2002:a05:7208:9594:b0:7e:5202:c8b4 with SMTP id gs20csp1961398rbb; Tue, 27 Feb 2024 06:43:12 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWsvIrCH3K4HgRJDT+CKf1nLGtByWgngbS8JLfQ+BJOunUAILQORuNuif8z/6Pp3UcXSTvq2dy2sHWg2DlyJmDiYGcvI8lA0cCCZKHJvg== X-Google-Smtp-Source: AGHT+IFFSaqIppDM+I0bynLZTU1BJWObcG5PutYfWT40YdhwV1Y121OFL9GICUmgdM4sNnM1unFh X-Received: by 2002:a05:6808:1508:b0:3c1:b099:d4d9 with SMTP id u8-20020a056808150800b003c1b099d4d9mr1335614oiw.12.1709044992015; Tue, 27 Feb 2024 06:43:12 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709044991; cv=pass; d=google.com; s=arc-20160816; b=qAr80oHDDykY12Kwx4P0mjEseWphOcEdU9oZJn+y/4SGHy58aI+PMAUr9PKDRfSDMN 7dVg/Try1ocU6nS/UhgRoJXxs5ynYT69Z0mVDSAaBRpRh4iu6JQgnX05Rkx8pX1bYs2a FioZtha56cYmwZv5xUTEyOIYHU8pddRE3DXzsyszL4m5lfx/KKwrfGhGTRFWmJHBp3mT lrQrmoQe6MzFbLVe597C91Wj3uHCuSnbr8eLchl8lrssxU6VCuT/ee2n8WULIf6+HapJ aPXBuiY/ydfmLAFyjg80tN2ZMLZD8ag6/zKRdNzfzmVRkjjzDfpRX8AYXTZn2032wW92 3hpg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=date:message-id:user-agent:cc:to:references:in-reply-to:from :subject:content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:dkim-signature; bh=5wRxguwF02eG9Kb9PwJOtcwnNVaUtat3SAs3X2CmxVs=; fh=2hEeNS8WQSS8QvLlxuM7v8+fhlxdB+W54MgOTUqEs/o=; b=F26r832J/eiMattsRyyPf6lnZxF9dIqcOHVfgfdOT4UntezQ+kushs7Np+WO1TnG5F HueRoRQ7ZYZFy04czoejc4vYc4e5ukVgijLNgqg8R/HzEbwfSUY8lz+wMw7PdCn3X/6g olZOUpN2wIjym9L4iptRR5AZCly9RczVrPt3wE+jtV40NeAogxzVKjWVqt249krbaYJR BxdL9R3dVfUmUhbFV1YaCxXknl9AQVej7vN5e9ZKzRKI57BhiBWRX+L2AzRD9q7EawKT +amtzoa/8om17f3JY+HVZdP4PKvG2qq3/trhlKe+YVrWt3WYMbno30UNOstCjN/VJIAr 6mRQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=EbNUhTWr; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-wireless+bounces-4096-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-wireless+bounces-4096-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id b18-20020ac87552000000b0042e0cd5095esi7234576qtr.89.2024.02.27.06.43.11 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Feb 2024 06:43:11 -0800 (PST) Received-SPF: pass (google.com: domain of linux-wireless+bounces-4096-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=EbNUhTWr; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-wireless+bounces-4096-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-wireless+bounces-4096-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 4C1DA1C222AD for ; Tue, 27 Feb 2024 14:43:11 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A565513B29B; Tue, 27 Feb 2024 14:43:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="EbNUhTWr" X-Original-To: linux-wireless@vger.kernel.org Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6BE435FBB3; Tue, 27 Feb 2024 14:43:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709044987; cv=none; b=As5++8SCX5ZBrou5qmDruEe4I++PuY7+hqBbkWC/Ky2JRrnNZNzg7eGjovr35KkNb3RYUwl73EkBewLW3tf8piFzNhB4AtLQZykumOhArUhfNWrca3zTuj830GNG+Vp2aYf34oV4k8N/O8gK5yR3a2rEsJluizjJ8WXSqweSnBs= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709044987; c=relaxed/simple; bh=DytXs2Kq0REoXTCul2OemM5lmaQM/IuOHuGspWgLqzE=; h=Content-Type:MIME-Version:Subject:From:In-Reply-To:References:To: Cc:Message-ID:Date; b=qlftXM16u2YlCI19/aGUe2aAPGxYwDzxAlZI0QMgVv+X0WWes6T02BC6kHS8Zs6veVwwCLRbu4toI16J591RVrQ/nqh3dJYHK5Us0Te3XNDBiN4ieQtyzE6QL2nFjW6ZIXSAGWTSUo2AkcTaprD9pDvADViw6VIcwnPuJuA9IOg= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=EbNUhTWr; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 81AC5C433F1; Tue, 27 Feb 2024 14:43:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1709044986; bh=DytXs2Kq0REoXTCul2OemM5lmaQM/IuOHuGspWgLqzE=; h=Subject:From:In-Reply-To:References:To:Cc:Date:From; b=EbNUhTWrqo+/uOMGcfFC5ZLud5wfMJbPHX8Otm3B0bpuLpcQ3IMmM+zlMSKf5Sn6z lvqLVvy7L6Z7skS7FNmTuqiz03t6SuTTHRTjXcsY0Et5wfVcs+D8cBCt4GmBjdr44s kQx9y0PKNpzvOO9a72dNEPyzfseNNNMNKTvsHWjxnaJpkUom7xBRPcfz6a6LC7LAzs ZGN+JQYRA1gbr+W4bzYJFKBD9GoLtd/w2U+4kEbFuHyvsIveXqj4xYaPG0HTy0BmrU i6+hCLqyBrWwjzF+cYrNSanCLqmWSXPhw6eg4UNevsFVK/MLqkX0ryXMs05kgQpoKk 3onbxDufNjDTQ== Content-Type: text/plain; charset="utf-8" Precedence: bulk X-Mailing-List: linux-wireless@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: Re: [PATCH][next] wifi: brcmfmac: fweh: Fix boot crash on Raspberry Pi 4 From: Kalle Valo In-Reply-To: References: To: "Gustavo A. R. Silva" Cc: Arend van Spriel , Nathan Chancellor , linux-wireless@vger.kernel.org, brcm80211@lists.linux.dev, brcm80211-dev-list.pdl@broadcom.com, linux-kernel@vger.kernel.org, "Gustavo A. R. Silva" , linux-hardening@vger.kernel.org User-Agent: pwcli/0.1.1-git (https://github.com/kvalo/pwcli/) Python/3.11.2 Message-ID: <170904498245.3524945.4143383846872449498.kvalo@kernel.org> Date: Tue, 27 Feb 2024 14:43:04 +0000 (UTC) "Gustavo A. R. Silva" wrote: > Fix boot crash on Raspberry Pi by moving the update to `event->datalen` > before data is copied into flexible-array member `data` via `memcpy()`. > > Flexible-array member `data` was annotated with `__counted_by(datalen)` > in commit 62d19b358088 ("wifi: brcmfmac: fweh: Add __counted_by for > struct brcmf_fweh_queue_item and use struct_size()"). The intention of > this is to gain visibility into the size of `data` at run-time through > its _counter_ (in this case `datalen`), and with this have its accesses > bounds-checked at run-time via CONFIG_FORTIFY_SOURCE and > CONFIG_UBSAN_BOUNDS. > > To effectively accomplish the above, we shall update the counter > (`datalen`), before the first access to the flexible array (`data`), > which was also done in the mentioned commit. > > However, commit edec42821911 ("wifi: brcmfmac: allow per-vendor event > handling") inadvertently caused a buffer overflow, detected by > FORTIFY_SOURCE. It moved the `event->datalen = datalen;` update to after > the first `data` access, at which point `event->datalen` was not yet > updated from zero (after calling `kzalloc()`), leading to the overflow > issue. > > This fix repositions the `event->datalen = datalen;` update before > accessing `data`, restoring the intended buffer overflow protection. :) > > Fixes: edec42821911 ("wifi: brcmfmac: allow per-vendor event handling") > Reported-by: Nathan Chancellor > Closes: https://gist.github.com/nathanchance/e22f681f3bfc467f15cdf6605021aaa6 > Tested-by: Nathan Chancellor > Signed-off-by: Gustavo A. R. Silva > Reviewed-by: Kees Cook > Acked-by: Arend van Spriel Patch applied to wireless-next.git, thanks. ec1aae190c77 wifi: brcmfmac: fweh: Fix boot crash on Raspberry Pi 4 -- https://patchwork.kernel.org/project/linux-wireless/patch/Zc+3PFCUvLoVlpg8@neat/ https://wireless.wiki.kernel.org/en/developers/documentation/submittingpatches