Received: by 2002:a89:48b:0:b0:1f5:f2ab:c469 with SMTP id a11csp1303664lqd; Thu, 25 Apr 2024 11:13:50 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWJcxGYoLwO5gq5mXaKU8gCo5TM3hBPDxLhXChK0zUo4rvF08V3PuwIWo8ndQO6miBkkaT7EFYrXalLnYxAZQgtGWHiHIqGlGBG0cOQ8A== X-Google-Smtp-Source: AGHT+IGr6HQMKAnPAm8YALii8Lbav3BzaIQsdowShL9+3UC1E7p/9UqZbdZvjqdUEnRPPrVDbxwS X-Received: by 2002:a05:6808:2025:b0:3c5:fcff:3979 with SMTP id q37-20020a056808202500b003c5fcff3979mr597196oiw.48.1714068829896; Thu, 25 Apr 2024 11:13:49 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1714068829; cv=pass; d=google.com; s=arc-20160816; b=YDay7/IflbdO/FYzq4W7cdD1PJNp5Qifysyeu2owYuw6BD4VuGLHlTIP7JsNYm6/OV 6i+tHGoM8QPGPCBYvuvCPejpFy2EzXNJSsw4faUbfobASgb5Es7ADE9s5GXXUGOV/j41 8s9ZAn9A8s1eaE1KSoQP2ZVlzjNUUpzLQJkJzNkfqSgBmhnCLShJX19N0UkPahaKyAuN ZeJMVm9Mtvbb0V+lpCcJiEVzWhk8MoAR4s3VrY+1nKWi32pCgZimXNFAttGwMZ70d4l3 elhsHpxKBINPIbuIt3j/39ArF8iijBa9s6z3Pu6coAKavocag9Q7iGbiLog5PH9Q5xg3 fydg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date:dkim-signature; bh=FQ2SZrFkCDYF/vLI1gJb2unZ198qlQZaqvOuV/egvJo=; fh=pC9Qk6bWE01Lqtbq4JR7DCXxQGDWz2I0lsDdzyzrVkA=; b=g4mOEMmHBljPnnArTkOglBKzXkiRwATT855JW8D70RKPSJgmnyeqjC0LlGeauRxxGh 2+i43+xugtJuGyf2hI+X+HgV8rEwmCDgFt5S1W0D8Y8LLZSSANUs04FlqGhs/239Vn+D JKZ+U4CYEwzFQ0a/zTgLT2uTE7wQK3P1QEfx+Y9ve4sNj+uAWiekQgq93maj8chuvi8S pNoq+Gf1usjJU7JsKNQ0gGA6plP72HBt79iQYkxuHYKHm1FLHeRV9P8TXefE3ENpK2Ai APTs7pwumi6GVuuEfDpwVCnuRfl8t/3F3FNl5VA9p7G3C8oOFGCs+J/uF/ALNhZBU1kp XH4g==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=ppFh1xjW; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-wireless+bounces-6869-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-wireless+bounces-6869-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 jf13-20020a0562142a4d00b0069b538caa0asi17966985qvb.14.2024.04.25.11.13.49 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 25 Apr 2024 11:13:49 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-wireless+bounces-6869-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=ppFh1xjW; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-wireless+bounces-6869-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-wireless+bounces-6869-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 9CB221C21623 for ; Thu, 25 Apr 2024 18:13:49 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 7F4A814F109; Thu, 25 Apr 2024 18:13:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="ppFh1xjW" 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 4BE1A14D457; Thu, 25 Apr 2024 18:13:44 +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=1714068825; cv=none; b=mCjujPIbcto8YbFR533NDsdaC6fGK1enDHHAGCNZPRp0rfUUoujOYxepeVIEUF538IENhnGW+NzJlHL0iavS1J/E5BbmUtjT2jjF5nDGVMrhqQgw+j8uniSmUfzD8FxJgy7DbLFUKN2Gv0lb3+SlqHhAHa3kfRR06Zy5+cUeis8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714068825; c=relaxed/simple; bh=3jpA0jxtOrM/Uqkdg7yxRM62YlSKAnUiGdGNzloi//4=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=i3gt/I003tbSU4c3OB4nrLMQI0GWd5zDUp1YIE0wBfgrsJlF1sAbksm982dS6PKDqq2nGV46IyOGrJgs493CRLOCD0gbf6Fgn/AkfV0kQhPe1Z2Lqd/Yr6wFK+Dn3o2+SPRR7dDKw65k4Ni484iIOZXh65NAOH8IiLF2sm7GIqU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=ppFh1xjW; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 11A35C113CC; Thu, 25 Apr 2024 18:13:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1714068824; bh=3jpA0jxtOrM/Uqkdg7yxRM62YlSKAnUiGdGNzloi//4=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=ppFh1xjWf2kci1FJhtjIrbEINq9USZ4fYIi8a+kYjfczOXkx3LmJ6AXUDy51ynuwK tgpzVirWkM798pCefQbee4sl4FkDYdAO0m8qjX0LdrdaAfzvKuECTIj/7KqePQNbyR 4XeC64zewqCWapZ14rt/FdWJIi3JIFJlGyqQvHC5STJiqWAqtKz8fjVh5UPOBvVsI9 UrmtHG+oFGXaAvna5kjygKMn9LLDOQ7FlelZTFh/es67PFyUd7PVvUv44hYdqNnyEr ECF6rv66wFKaPb3KolI2i1AvRNTHe5FwMoyqudb2k+1pd7uoPBqegjb3Adxk4dAIH1 ObHdNUgyXjhmg== Date: Thu, 25 Apr 2024 11:13:42 -0700 From: Nathan Chancellor To: Kees Cook Cc: Johannes Berg , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , linux-wireless@vger.kernel.org, netdev@vger.kernel.org, Jeff Johnson , "Gustavo A. R. Silva" , linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org Subject: Re: [PATCH] wifi: nl80211: Avoid address calculations via out of bounds array indexing Message-ID: <20240425181342.GA657080@dev-arch.thelio-3990X> References: <20240424220057.work.819-kees@kernel.org> Precedence: bulk X-Mailing-List: linux-wireless@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20240424220057.work.819-kees@kernel.org> On Wed, Apr 24, 2024 at 03:01:01PM -0700, Kees Cook wrote: > Before request->channels[] can be used, request->n_channels must be set. > Additionally, address calculations for memory after the "channels" array > need to be calculated from the allocation base ("request") rather than > via the first "out of bounds" index of "channels", otherwise run-time > bounds checking will throw a warning. > > Reported-by: Nathan Chancellor > Fixes: e3eac9f32ec0 ("wifi: cfg80211: Annotate struct cfg80211_scan_request with __counted_by") > Signed-off-by: Kees Cook Tested-by: Nathan Chancellor > --- > Cc: Johannes Berg > Cc: "David S. Miller" > Cc: Eric Dumazet > Cc: Jakub Kicinski > Cc: Paolo Abeni > Cc: linux-wireless@vger.kernel.org > Cc: netdev@vger.kernel.org > --- > net/wireless/nl80211.c | 14 +++++++------- > 1 file changed, 7 insertions(+), 7 deletions(-) > > diff --git a/net/wireless/nl80211.c b/net/wireless/nl80211.c > index f391b4055944..f1ed0981147e 100644 > --- a/net/wireless/nl80211.c > +++ b/net/wireless/nl80211.c > @@ -9163,6 +9163,7 @@ static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info) > struct wiphy *wiphy; > int err, tmp, n_ssids = 0, n_channels, i; > size_t ie_len, size; > + size_t ssids_offset, ie_offset; > > wiphy = &rdev->wiphy; > > @@ -9208,21 +9209,20 @@ static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info) > return -EINVAL; > > size = struct_size(request, channels, n_channels); > + ssids_offset = size; > size = size_add(size, array_size(sizeof(*request->ssids), n_ssids)); > + ie_offset = size; > size = size_add(size, ie_len); > request = kzalloc(size, GFP_KERNEL); > if (!request) > return -ENOMEM; > + request->n_channels = n_channels; > > if (n_ssids) > - request->ssids = (void *)&request->channels[n_channels]; > + request->ssids = (void *)request + ssids_offset; > request->n_ssids = n_ssids; > - if (ie_len) { > - if (n_ssids) > - request->ie = (void *)(request->ssids + n_ssids); > - else > - request->ie = (void *)(request->channels + n_channels); > - } > + if (ie_len) > + request->ie = (void *)request + ie_offset; > > i = 0; > if (scan_freqs) { > -- > 2.34.1 >