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 X-Spam-Level: X-Spam-Status: No, score=-24.7 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,MENTIONS_GIT_HOSTING,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C1186C43461 for ; Wed, 5 May 2021 16:54:46 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A2298613B4 for ; Wed, 5 May 2021 16:54:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236425AbhEEQyN (ORCPT ); Wed, 5 May 2021 12:54:13 -0400 Received: from mail.kernel.org ([198.145.29.99]:49544 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235985AbhEEQpY (ORCPT ); Wed, 5 May 2021 12:45:24 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 25741613FC; Wed, 5 May 2021 16:36:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1620232572; bh=o+vXLCwrGRdUFyTL8oKuaI1v7wtRrNgfYd2+jq2f8JQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=JLspGd9O97b83AlfX6q8wTFkYY7rq9mmXoTSD4rXDmxOQt/30RjpiZyJI8ps97iMZ 2BshBG1Zosc2mHVqrFSHHM3MZBGdRJ8K4gp8PfSOln/CAF6la6FrmcfN0uegaj26Z9 rCX394cETmopBAVu2g33MWuKjEcFSyOx+hIXJB6N9p2TdpAh/zs2pegk4NY8MvGLXm 40Cp7kG6/KoUoNnkR513EI/z14MU3ogtO/iYsfbtdlPcvMR+UOpB84juCqhlr5j+BF T2GoxjQ9wd6CULTvaAZHX0FJ7E3IISaNayfhP9nr224jYICSxE0zuVfWmjZIVBGdy7 1k81LkWQV5cYA== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: "Gustavo A. R. Silva" , kernel test robot , "David S . Miller" , Sasha Levin , netdev@vger.kernel.org Subject: [PATCH AUTOSEL 5.11 081/104] ethtool: ioctl: Fix out-of-bounds warning in store_link_ksettings_for_user() Date: Wed, 5 May 2021 12:33:50 -0400 Message-Id: <20210505163413.3461611-81-sashal@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210505163413.3461611-1-sashal@kernel.org> References: <20210505163413.3461611-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: linux-kernel@vger.kernel.org From: "Gustavo A. R. Silva" [ Upstream commit c1d9e34e11281a8ba1a1c54e4db554232a461488 ] Fix the following out-of-bounds warning: net/ethtool/ioctl.c:492:2: warning: 'memcpy' offset [49, 84] from the object at 'link_usettings' is out of the bounds of referenced subobject 'base' with type 'struct ethtool_link_settings' at offset 0 [-Warray-bounds] The problem is that the original code is trying to copy data into a some struct members adjacent to each other in a single call to memcpy(). This causes a legitimate compiler warning because memcpy() overruns the length of &link_usettings.base. Fix this by directly using &link_usettings and _from_ as destination and source addresses, instead. This helps with the ongoing efforts to globally enable -Warray-bounds and get us closer to being able to tighten the FORTIFY_SOURCE routines on memcpy(). Link: https://github.com/KSPP/linux/issues/109 Reported-by: kernel test robot Signed-off-by: Gustavo A. R. Silva Signed-off-by: David S. Miller Signed-off-by: Sasha Levin --- net/ethtool/ioctl.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/net/ethtool/ioctl.c b/net/ethtool/ioctl.c index 771688e1b0da..2603966da904 100644 --- a/net/ethtool/ioctl.c +++ b/net/ethtool/ioctl.c @@ -489,7 +489,7 @@ store_link_ksettings_for_user(void __user *to, { struct ethtool_link_usettings link_usettings; - memcpy(&link_usettings.base, &from->base, sizeof(link_usettings)); + memcpy(&link_usettings, from, sizeof(link_usettings)); bitmap_to_arr32(link_usettings.link_modes.supported, from->link_modes.supported, __ETHTOOL_LINK_MODE_MASK_NBITS); -- 2.30.2