From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 14FDACCA47E for ; Tue, 21 Jun 2022 20:57:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1355089AbiFUU5d (ORCPT ); Tue, 21 Jun 2022 16:57:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54764 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1355212AbiFUU4n (ORCPT ); Tue, 21 Jun 2022 16:56:43 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E8E3331932; Tue, 21 Jun 2022 13:50:40 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id B433E61883; Tue, 21 Jun 2022 20:50:18 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 56194C3411C; Tue, 21 Jun 2022 20:50:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1655844618; bh=3PjshUGZxQk6YNxZZzX8HOQM3GtVU4b/kpi+bYMZqLo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=aqzpAkUXNxZcNlnjkgH4DcavXrtt1DD5T9cHBtrMMDplc9Fan6BbzefKNOuITuUtN 0le0R3OcE0+yc6phnXxS4Ob8fnjZz9d/rcdJnYATdFRE8FQ2I48rs3bH122pVQ+yCn dagJqEM55Fdt3P0lkyQRzYTMHs1i/1G88RvCBANnk1L1oD2Za93AshDuCrPx0JAK9a 7WUjdzXqknhWqKul/b8lwMkXX8wqrURSDi8ofJFQPlvoEV2c+uL5Hvx8Wh2Q2smVhH tX1Zu3K6twau5iGjiXU3lkcYywRI6mwL0kfm1E7Aojbt36B0k+1xqvT7gi552LMODS NeaQfIPmFgLxw== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Kees Cook , Greg Kroah-Hartman , Fabio Aiuto , Hans de Goede , linux-staging@lists.linux.dev, Sasha Levin , straube.linux@gmail.com, arnd@arndb.de Subject: [PATCH AUTOSEL 5.17 03/20] staging: rtl8723bs: Allocate full pwep structure Date: Tue, 21 Jun 2022 16:49:53 -0400 Message-Id: <20220621205010.250185-3-sashal@kernel.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220621205010.250185-1-sashal@kernel.org> References: <20220621205010.250185-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Kees Cook [ Upstream commit 67ea0a2adbf667cd6da4965fbcfd0da741035084 ] The pwep allocation was always being allocated smaller than the true structure size. Avoid this by always allocating the full structure. Found with GCC 12 and -Warray-bounds: ../drivers/staging/rtl8723bs/os_dep/ioctl_linux.c: In function 'rtw_set_encryption': ../drivers/staging/rtl8723bs/os_dep/ioctl_linux.c:591:29: warning: array subscript 'struct ndis_802_11_wep[0]' is partly outside array bounds of 'void[25]' [-Warray-bounds] 591 | pwep->length = wep_total_len; | ^~ Cc: Greg Kroah-Hartman Cc: Fabio Aiuto Cc: Hans de Goede Cc: linux-staging@lists.linux.dev Signed-off-by: Kees Cook Link: https://lore.kernel.org/r/20220608215512.1070847-1-keescook@chromium.org Signed-off-by: Greg Kroah-Hartman Signed-off-by: Sasha Levin --- drivers/staging/rtl8723bs/os_dep/ioctl_linux.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/drivers/staging/rtl8723bs/os_dep/ioctl_linux.c b/drivers/staging/rtl8723bs/os_dep/ioctl_linux.c index ece97e37ac91..30374a820496 100644 --- a/drivers/staging/rtl8723bs/os_dep/ioctl_linux.c +++ b/drivers/staging/rtl8723bs/os_dep/ioctl_linux.c @@ -90,7 +90,8 @@ static int wpa_set_encryption(struct net_device *dev, struct ieee_param *param, if (wep_key_len > 0) { wep_key_len = wep_key_len <= 5 ? 5 : 13; wep_total_len = wep_key_len + FIELD_OFFSET(struct ndis_802_11_wep, key_material); - pwep = kzalloc(wep_total_len, GFP_KERNEL); + /* Allocate a full structure to avoid potentially running off the end. */ + pwep = kzalloc(sizeof(*pwep), GFP_KERNEL); if (!pwep) { ret = -ENOMEM; goto exit; @@ -582,7 +583,8 @@ static int rtw_set_encryption(struct net_device *dev, struct ieee_param *param, if (wep_key_len > 0) { wep_key_len = wep_key_len <= 5 ? 5 : 13; wep_total_len = wep_key_len + FIELD_OFFSET(struct ndis_802_11_wep, key_material); - pwep = kzalloc(wep_total_len, GFP_KERNEL); + /* Allocate a full structure to avoid potentially running off the end. */ + pwep = kzalloc(sizeof(*pwep), GFP_KERNEL); if (!pwep) goto exit; -- 2.35.1