Received: by 2002:ab2:6816:0:b0:1f9:5764:f03e with SMTP id t22csp1025692lqo; Fri, 17 May 2024 08:33:55 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUH8lStAO056VD/nRGUcnwaX1IJCLzQaPx2OLlIm/zzTJRAgXxPCgLJhdak2yC4Vvw6GsIvrilKJBn4X8y2oy6x7m9QvSEWuTF0XFm8RQ== X-Google-Smtp-Source: AGHT+IHr6MRil/0RfaXe9GRxsvzjCTBuTxrxE0NQXTDycJrfeqdFoTK2kiAbFg5jltNIPtPYBfFw X-Received: by 2002:a05:6a21:6da1:b0:1af:acb1:84bb with SMTP id adf61e73a8af0-1afde09ec5dmr24654661637.4.1715960035595; Fri, 17 May 2024 08:33:55 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715960035; cv=pass; d=google.com; s=arc-20160816; b=0nonwicrj1bGARVu9mbkeBnWRYFltEH9QZaTH+cdiKjMI+7dskrFEvPiMSsbjfoExP Mf5uWs2Ikj9er2QUA9ExkPstFMaFoCqExuyezfkrOj+aLePYy3Y/Q2zQx7Rp39u2wJtH 6q5HTkmmyURd7IKJVKJCXz8nlECAgf2awSJwobjS2/Ke3FTGk7/iINT9hXTfDJAg2+Bx GpKaypvtaJ8JBz86j632jZI9clwE9VfitmwzNeJqGKEo0nMuOZVTPjvctugsbmUgmucA VP1tz1VO0Fc/EcRj+GRx8kDv1Kc7L+DPGAmGrZi2hvvaaClK8iypwK4r9hyP5LNmxWi+ +ujw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=IoGGzC4UPODFkDplsAMcg9yw1a+vUefTbBgLr2uPevo=; fh=s7iCXePv5sDIb6YuoGGYNxrO/zNMR78KrqJ4afN3auI=; b=LFiJqfjcQmT/TBRpmmuG6gc2BQ7vJ6Nig+SfZHseBW+xCyhk5Cx3TdgEh9TJZpKZB2 nnwTjfSzY7LSIqLvvb6vWRQosVj1PzVGmJE/FMVp95qgtp6/T/MykkNNFvwRoQO0e8sC y1yy5+NPp9Ul9/+71b3NKngTzi83377R44ZsrB10kBMb4iFgbKBZMOH3+h7ZXNJPvYjI e4J6ymuBRPFre1/E8cTsJVDKdpwEntwkX2EApGHwXfL4v16VWj7dutjHHPQbdPde4ETz FPLsRA7EdHhjHpLf8USikEXuOCxLZPBfJbqdMbavXnhIOJx/YDNEpK/mS6X4nieB3i3b q0Kw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@yandex.ru header.s=mail header.b=XAr7cU37; arc=pass (i=1 spf=pass spfdomain=yandex.ru dkim=pass dkdomain=yandex.ru dmarc=pass fromdomain=yandex.ru); spf=pass (google.com: domain of linux-wireless+bounces-7788-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-wireless+bounces-7788-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=yandex.ru Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id 41be03b00d2f7-65848e9714esi4162728a12.118.2024.05.17.08.33.55 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 17 May 2024 08:33:55 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-wireless+bounces-7788-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@yandex.ru header.s=mail header.b=XAr7cU37; arc=pass (i=1 spf=pass spfdomain=yandex.ru dkim=pass dkdomain=yandex.ru dmarc=pass fromdomain=yandex.ru); spf=pass (google.com: domain of linux-wireless+bounces-7788-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-wireless+bounces-7788-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=yandex.ru 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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 8D033281804 for ; Fri, 17 May 2024 15:33:54 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 4F37212D212; Fri, 17 May 2024 15:33:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=yandex.ru header.i=@yandex.ru header.b="XAr7cU37" X-Original-To: linux-wireless@vger.kernel.org Received: from forward100b.mail.yandex.net (forward100b.mail.yandex.net [178.154.239.147]) (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 AF38654673; Fri, 17 May 2024 15:33:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=178.154.239.147 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715960032; cv=none; b=XfOMUYTEz453ZX8GQgS6tDZT5h1RfCHzTl1qxwXWUq/npViWF5oeVqQZ2nRvYQpBPF+hKgBZqwx2HqVhBNrbCo2MnqBbG/rznRSuLj2B3CAPXfxdDuJXB6FXewxJ2sHb4m4c5zq83B/Xigsr63gYQUwXFMvLc+k6TeLkKW6H8QQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715960032; c=relaxed/simple; bh=DO0jPXx3Xa5gYc9xzYitx5U9CfWOMS2FByDGkugToec=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=TA5P1FBdXL+xWmq3MipXp9hJPTw+1KrkJsaSP5KEQNkUFU+7inalDU+gIAcffWk1lMAgXIgmT9+gWZYR7oXGbd0K7kIxIPCFcV30wVPtKglLW3ii7izcSvrQoUvBhZeNRJ1E5oy0UZzU0R4LSphSxFW9Yh5yJKT+yKjTVp2jukU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=yandex.ru; spf=pass smtp.mailfrom=yandex.ru; dkim=pass (1024-bit key) header.d=yandex.ru header.i=@yandex.ru header.b=XAr7cU37; arc=none smtp.client-ip=178.154.239.147 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=yandex.ru Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=yandex.ru Received: from mail-nwsmtp-smtp-production-main-31.sas.yp-c.yandex.net (mail-nwsmtp-smtp-production-main-31.sas.yp-c.yandex.net [IPv6:2a02:6b8:c08:de2c:0:640:e39b:0]) by forward100b.mail.yandex.net (Yandex) with ESMTPS id 93DFF60ACA; Fri, 17 May 2024 18:33:38 +0300 (MSK) Received: by mail-nwsmtp-smtp-production-main-31.sas.yp-c.yandex.net (smtp/Yandex) with ESMTPSA id aXHWQ33Zu8c0-tBlIXqJa; Fri, 17 May 2024 18:33:38 +0300 X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex.ru; s=mail; t=1715960018; bh=IoGGzC4UPODFkDplsAMcg9yw1a+vUefTbBgLr2uPevo=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=XAr7cU37My2NdN5w4fnEPt1+Df9seakgQ8AK7BXM+RSee2PkVYjplqZ1rW5FQ3UVo da4LuibSFGR59lFzMHBhVCf/+K6wD1QuFmxihgX3DYzlf0J22biQ/QeqO4kKAbwTgJ tECdd7lLGBm5RWZJ9v/bY2qVW4cGUaNh+3CwzrF0= Authentication-Results: mail-nwsmtp-smtp-production-main-31.sas.yp-c.yandex.net; dkim=pass header.i=@yandex.ru From: Dmitry Antipov To: Johannes Berg , Kees Cook , linux-wireless@vger.kernel.org, linux-hardening@vger.kernel.org Cc: Dmitry Antipov Subject: [PATCH 2/2] wifi: mac80211: fix UBSAN noise in ieee80211_prep_hw_scan() Date: Fri, 17 May 2024 18:33:32 +0300 Message-ID: <20240517153332.18271-2-dmantipov@yandex.ru> X-Mailer: git-send-email 2.45.0 In-Reply-To: <20240517153332.18271-1-dmantipov@yandex.ru> References: <20240517153332.18271-1-dmantipov@yandex.ru> Precedence: bulk X-Mailing-List: linux-wireless@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit When testing the previous patch with CONFIG_UBSAN_BOUNDS, I've noticed the following: UBSAN: array-index-out-of-bounds in net/mac80211/scan.c:372:4 index 0 is out of range for type 'struct ieee80211_channel *[]' CPU: 0 PID: 1435 Comm: wpa_supplicant Not tainted 6.9.0+ #1 Hardware name: LENOVO 20UN005QRT/20UN005QRT <...BIOS details...> Call Trace: dump_stack_lvl+0x2d/0x90 __ubsan_handle_out_of_bounds+0xe7/0x140 ? timerqueue_add+0x98/0xb0 ieee80211_prep_hw_scan+0x2db/0x480 [mac80211] ? __kmalloc+0xe1/0x470 __ieee80211_start_scan+0x541/0x760 [mac80211] rdev_scan+0x1f/0xe0 [cfg80211] nl80211_trigger_scan+0x9b6/0xae0 [cfg80211] ... Since '__ieee80211_start_scan()' leaves 'hw_scan_req->req.n_channels' uninitialized, actual boundaries of 'hw_scan_req->req.channels' can't be checked in 'ieee80211_prep_hw_scan()'. Although an initialization of 'hw_scan_req->req.n_channels' introduces some confusion around allocated vs. used VLA members, this shouldn't be a problem since everything is correctly adjusted soon in 'ieee80211_prep_hw_scan()'. Cleanup 'kmalloc()' math in '__ieee80211_start_scan()' by using the convenient 'struct_size()' as well. Signed-off-by: Dmitry Antipov --- net/mac80211/scan.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/net/mac80211/scan.c b/net/mac80211/scan.c index 3da1c5c45035..ab2a11a02673 100644 --- a/net/mac80211/scan.c +++ b/net/mac80211/scan.c @@ -745,14 +745,19 @@ static int __ieee80211_start_scan(struct ieee80211_sub_if_data *sdata, } local->hw_scan_req = kmalloc( - sizeof(*local->hw_scan_req) + - req->n_channels * sizeof(req->channels[0]) + - local->hw_scan_ies_bufsize, GFP_KERNEL); + (struct_size(local->hw_scan_req, + req.channels, req->n_channels) + + local->hw_scan_ies_bufsize), GFP_KERNEL); if (!local->hw_scan_req) return -ENOMEM; local->hw_scan_req->req.ssids = req->ssids; local->hw_scan_req->req.n_ssids = req->n_ssids; + /* None of the channels are actually set + * up but let UBSAN know the boundaries. + */ + local->hw_scan_req->req.n_channels = req->n_channels; + ies = (u8 *)local->hw_scan_req + sizeof(*local->hw_scan_req) + req->n_channels * sizeof(req->channels[0]); -- 2.45.1