Received: by 2002:ab2:1689:0:b0:1f7:5705:b850 with SMTP id d9csp1910171lqa; Tue, 30 Apr 2024 03:02:24 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXqbRmDdvL4DtP+S8TbFiUkImW3XU5qLRYVzR2Nt5glcL6h5hUhuCsi+9o36MNPzFT0ZMVMZtWB3Il86AoT7CdnxMt+xKnhKKeTPqjFSg== X-Google-Smtp-Source: AGHT+IEOMsAKqIFv6uCpisaU4AkTTJ8Zi77hcRlz64AL5yOkP4/P1qMokz2lEDY99pPDVcCb97tk X-Received: by 2002:a05:6512:1108:b0:51d:9f10:71b7 with SMTP id l8-20020a056512110800b0051d9f1071b7mr6741238lfg.28.1714471343930; Tue, 30 Apr 2024 03:02:23 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1714471343; cv=pass; d=google.com; s=arc-20160816; b=OX4/SwfnzgdhqkPvsaZj+s1G9fcli3fzkQU+yNOWwhM+lQCQMQ/dr1uM97bVtZKYV1 ejebsXeV/LZL2pdD45LWPujWsvkitcsRozDnp6q6915xzc78x2z+0R+3wMPmq4h2SiVC nHMxvXoqXLV7aZhiu/30x9ADi/oo0UrFe3rHghiMOlZ62MQX5Wx8ka040KguQrhmavHZ wgXlI6BIK1BkbCnZyx+8DSawWtqTcP2yVSSqIiOzvyntkKow8t5QmSFaDl5h12Ky+qzK Eah9IpBWi47t6bGpVE0L4AijDFxQQkGw/VZlGTp7p25o/usv4Qmt62WQ/hJ34LMfJvN/ iIaQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:list-unsubscribe:list-subscribe:list-id:precedence :user-agent:content-transfer-encoding:references:in-reply-to:date:cc :to:from:subject:message-id:dkim-signature; bh=nOTmeD3yZAzeGoMmikPvoxrLw1CeqyXxgI5qLq+cYSw=; fh=x4Zm7FEAGa6OpwfoZJGN7wAizHN5uO9tGIywDpcnHrU=; b=DqHZ4CLIBpdtkX6IOa7zhCBjV3OOWwDLM5APczb0xPNFSvkhU2Rz3p03Vv84UoZjCC 7Pf8qad11Gg1JBSAJtDWDhJ76R40l0aFEtmqA5MNLOPvF8pQx6xjxyD/tFYZXFNqTKLQ J+FsARm72vgQyJfgi5vDYFkzm5oTYt2KS3y8sQwURxBj9JUv9Vx9zqDoYl2nmj/a1W95 J6Wgbe4VFC5hOKhU0KEOXqKEkYD2dQInU/oS2sBrnyy0n7/CxFhOcu/eaKu2IxzVDti0 9PDAJ1JglWPg1IYGPORgxAGPf5kyMYlB1Uqki9ZHIQ/HHaAb+NgiOpp6eYRQqtMAY63V P70w==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@sipsolutions.net header.s=mail header.b=KNvbA8vd; arc=pass (i=1 spf=pass spfdomain=sipsolutions.net dkim=pass dkdomain=sipsolutions.net dmarc=pass fromdomain=sipsolutions.net); spf=pass (google.com: domain of linux-kernel+bounces-163737-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-163737-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=REJECT dis=NONE) header.from=sipsolutions.net Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id b19-20020a1709063f9300b00a4734b06c8csi15321433ejj.630.2024.04.30.03.02.23 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Apr 2024 03:02:23 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-163737-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=@sipsolutions.net header.s=mail header.b=KNvbA8vd; arc=pass (i=1 spf=pass spfdomain=sipsolutions.net dkim=pass dkdomain=sipsolutions.net dmarc=pass fromdomain=sipsolutions.net); spf=pass (google.com: domain of linux-kernel+bounces-163737-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-163737-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=REJECT dis=NONE) header.from=sipsolutions.net 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 9CA1F1F24361 for ; Tue, 30 Apr 2024 10:02:23 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 0CD57129A8E; Tue, 30 Apr 2024 10:02:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=sipsolutions.net header.i=@sipsolutions.net header.b="KNvbA8vd" Received: from sipsolutions.net (s3.sipsolutions.net [168.119.38.16]) (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 4BE3E3A8CB; Tue, 30 Apr 2024 10:01:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=168.119.38.16 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714471329; cv=none; b=bB3+f2UdjeA31lNQsmrba9ZDl6kpWNKTlaMNet6HFA0qX2h+OqJhn/0IUaGYVvvQawPA0WHwn3B50rL9tdzOvvEWWoXmEg5nBtzB9ENEcev4a0pWQsGeVI3c0V9m9RvQ35WNbdTOfbGRJzGiBXrmck/KQYWa27Jv6seFOQ2VDgM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714471329; c=relaxed/simple; bh=RsGWFUaXZsIM9XF86rOQ2hjMpDFzHHbu7QElEsefk1k=; h=Message-ID:Subject:From:To:Cc:Date:In-Reply-To:References: Content-Type:MIME-Version; b=QZtA74B3fcOJTn4OrqZg/hT8B0QUmytBm85YAZRG7iREL500yHPExeNPPcv7FrezqFNFH8+6enVb7aMTmLzDBGKik8sbwOUmr1Zxka4baWtUStpWNjsCLOWGiCWnU2ShD6b+cMMNuTHc3toQhUyA//uYftJUc6+fsMmMxEUt0wc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=sipsolutions.net; spf=pass smtp.mailfrom=sipsolutions.net; dkim=pass (2048-bit key) header.d=sipsolutions.net header.i=@sipsolutions.net header.b=KNvbA8vd; arc=none smtp.client-ip=168.119.38.16 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=sipsolutions.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=sipsolutions.net DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sipsolutions.net; s=mail; h=MIME-Version:Content-Transfer-Encoding: Content-Type:References:In-Reply-To:Date:Cc:To:From:Subject:Message-ID:Sender :Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From:Resent-To: Resent-Cc:Resent-Message-ID; bh=nOTmeD3yZAzeGoMmikPvoxrLw1CeqyXxgI5qLq+cYSw=; t=1714471324; x=1715680924; b=KNvbA8vdM7Ulcwq3mZlLHwIta3+5ReBfw2Z0mU4stAswSEQ urB4mH+emqF6umRP/oao+hdZz2qCcB29q9zfGzGG8caw+M3tKvAl/rAoXul6O82s+Cs+XoCZFoi+m n5fuhWadIG2fUctooNUx0vsfyYWDOEOVBdilAOS4Cme1WCZQJ6NyInZQOySkeuyWb0HXw2rOUS93E yZnyUrsCUSPO9lXeotvYVqtdh3K5tsXyWUY+TkvkAZg5EdLhXbDkhYHiwxpIXdhaHmt+oixvpianQ CdURoEGGopZU/QOT1c4amPQ9aQQvcfGkSYsl/LHbLt8GI1TwfwslRiYSrbUfJRTw==; Received: by sipsolutions.net with esmtpsa (TLS1.3:ECDHE_X25519__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim 4.97) (envelope-from ) id 1s1kJ0-0000000E5yC-0RB5; Tue, 30 Apr 2024 12:01:46 +0200 Message-ID: Subject: Re: [PATCH] wifi: nl80211: Avoid address calculations via out of bounds array indexing From: Johannes Berg To: Kees Cook Cc: Nathan Chancellor , "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 Date: Tue, 30 Apr 2024 12:01:44 +0200 In-Reply-To: <20240424220057.work.819-kees@kernel.org> References: <20240424220057.work.819-kees@kernel.org> Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable User-Agent: Evolution 3.50.4 (3.50.4-1.fc39) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-malware-bazaar: not-scanned On Wed, 2024-04-24 at 15:01 -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. >=20 > Reported-by: Nathan Chancellor > Fixes: e3eac9f32ec0 ("wifi: cfg80211: Annotate struct cfg80211_scan_reque= st with __counted_by") While I was weighing whether or not to apply this for 6.9 still ... > + request->n_channels =3D n_channels; > =20 > if (n_ssids) > - request->ssids =3D (void *)&request->channels[n_channels]; > + request->ssids =3D (void *)request + ssids_offset; This really doesn't even seem right, shouldn't do pointer arithmetic on void pointers. Same applies below too. And also if you set n_channels before, perhaps it's actually OK to get a pointer to *after*? Not sure though. johannes