Received: by 2002:a05:7208:9594:b0:7e:5202:c8b4 with SMTP id gs20csp1802767rbb; Tue, 27 Feb 2024 01:20:21 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCW+uSpigjGvMpdCJNx8M/9gj4LytVQ17kevTs6CIh+tNtwovz5f7m4bj/FvzwtP2jS08GcJe23Oij7b4oWT5lYaUCwdsbgOfRn/6EADkQ== X-Google-Smtp-Source: AGHT+IH/4MF6f1YNDOV/WD+nsooZ5WMqdzyZBRRCE93BJ8+tUORny/W1m8QNn/TJ/l7NfmmC5jES X-Received: by 2002:a17:907:209a:b0:a41:309d:8a2d with SMTP id pv26-20020a170907209a00b00a41309d8a2dmr7033799ejb.58.1709025621750; Tue, 27 Feb 2024 01:20:21 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709025621; cv=pass; d=google.com; s=arc-20160816; b=FM6faOzDZoSDBWIhyhlwUlnIlnsZzRKkkM/ID0CwjqsLWgT6w0M2bKs2un/5vhDBgm DhL1LJNAAG60p/2wdnFDICblzl0ZlsMUzd207PMgfEM68Vz2Ub1qKeEgooqhiMhOZccL J6qwadm+yHHO6k7SygGo6tU4qeN/KiABRGsLXFLxDxwxMohQJeTP2NJf6txoF1lcrcly ED3O57w6eYUqwincc370VNIlz5xvEzNJ95TpqbrPitECFoxCZqwWRkf1u4hxVHauoogM AmKYrCmIyCCZGwLRyNPQBp19wazxKb9MuqVhqBXdrYaEyDC04SHedrpU67re0uxxvueo C7UA== 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=syLh/TDRbU+I68Y2Mn3yV3k5NEVFNzr4+hK/yvZS9Dw=; fh=2hEeNS8WQSS8QvLlxuM7v8+fhlxdB+W54MgOTUqEs/o=; b=xL8IBJqsMd/uB3eZElH58L3c47O9SgF5Qz5WzMlMRkAo9wlvPIWgZmD02lUiRMbAuU DRN+xyNMEnNtND0qJGYaAVHadoxO0Ljahg94PY+riWfukFHMCffzMG1Nl+QsE+lQnLHb yCnkE4m8lj6jDvOAnGiXcrhlvSch3WEdR4A1RZRX0IZoOVj/crGJzHF0v5aKOLQJb6eL KxWWUx3X2rhJLF59W20USK9Q8g5O3OqOsvJ6xkZWgO6t1qpjzGZLIcz9oxUXGJp18wqW ZqaWYwnajbw+ZdXiSBUk5cBWgQXsAQA0HHa4RIXOA9aDokNCSh69afuWq8hjitdgqbg6 jMQQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=jPM2wtJT; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-82946-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-82946-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id gx17-20020a170906f1d100b00a3e473bf9cesi570596ejb.887.2024.02.27.01.20.21 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Feb 2024 01:20:21 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-82946-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=jPM2wtJT; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-82946-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-82946-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 am.mirrors.kernel.org (Postfix) with ESMTPS id 81F931F22ED7 for ; Tue, 27 Feb 2024 09:20:21 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 7A3241369A0; Tue, 27 Feb 2024 09:19:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="jPM2wtJT" 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 8E98A13664A; Tue, 27 Feb 2024 09:19:55 +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=1709025595; cv=none; b=kRjQJBpM4JLvEJHjMr9fRl0WIXVMeTPXiFETvlVcQloEq52DFxwkkH4vblNpho96u5SYusuhF/uRQs3pxRE+yM43GTOTGy7MeBPr8VA+unft2RE8Efhikcq42VMLjpG13VAjUMRFkhCyu8lwA0eDv7HWVTbSKXn353OZ3pYkexQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709025595; c=relaxed/simple; bh=4FKpQ2YxhRM1cS9JvwGrN9mJcPARYZbWsBsplFmE57w=; h=Content-Type:MIME-Version:Subject:From:In-Reply-To:References:To: Cc:Message-ID:Date; b=fEeA84JfLENS1BPQgC0BKwZxPQZZv9y807U23SuNHDtIR4drXCmMmvUHKwxFBj8hyViROmS2V9zOKJz49HyTtnJfjJm5Lotk6/AmJQhsdFZXNRJ41j4PwI27FMT0jNYEScjeIoIjaa3CiHoc/Qm/NMJn0cWb9f+7j9x8YNCl5wI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=jPM2wtJT; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3FEACC433F1; Tue, 27 Feb 2024 09:19:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1709025595; bh=4FKpQ2YxhRM1cS9JvwGrN9mJcPARYZbWsBsplFmE57w=; h=Subject:From:In-Reply-To:References:To:Cc:Date:From; b=jPM2wtJTHyWKh4fNtYM9y0G1BAyPnS/qGRUR/VbivdAJTPr7wGgbuuqenpnx+Te2X b/2ePMzsnfZWFfvZtKjuNvKLq9kIkzPYhBYJ703NFRQNusIT1AWV8ATgJjrY0IcpS9 bgTKUDEEAzRqBBKgjJdTSd5wUxfMn2h9heYZ9D3H6DLfqWlqXR8gGYTX16I0eRj24d pcHUikBx7/0JgxKXaQ2kS974YfcU59GQh72M4Yc/CP/4tdUtEkiV/Nx/s7WsqWgZbQ wWcvZW65ZdwnZYRKWlbaOR+yRCOsTdKgmTqpriFzw7jT8Vjq9vkfat5IxsFo2t5JG+ wX14nOE3RDc4g== Content-Type: text/plain; charset="utf-8" Precedence: bulk X-Mailing-List: linux-kernel@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: <170902559101.3280425.2706190192200235643.kvalo@kernel.org> Date: Tue, 27 Feb 2024 09:19:53 +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 Arend, ack? -- https://patchwork.kernel.org/project/linux-wireless/patch/Zc+3PFCUvLoVlpg8@neat/ https://wireless.wiki.kernel.org/en/developers/documentation/submittingpatches