Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp205362pxj; Tue, 18 May 2021 01:13:07 -0700 (PDT) X-Google-Smtp-Source: ABdhPJytpyQGKBkR8QKOX0q+RLLq8HuqUndk8dvoKVGXuBJrpoI7JxO/zdDk/Qc7+Er25ngaKF8Q X-Received: by 2002:a05:6638:2181:: with SMTP id s1mr4215405jaj.66.1621325587319; Tue, 18 May 2021 01:13:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621325587; cv=none; d=google.com; s=arc-20160816; b=NyRN+PyyGxxbq8ARupaC2VkSPQqtYdYz85GwGyy2M16RlwWR9/f6RwpoxMYNX0Z1oQ 8AAVzZNYvsg0uOI7QlZJteW1nA2te0hpgKlR1dsZ95sBjYXbssjFrdfw7f0OeXXlue2Z vfmEM/wmQ1UqAKUUz/SoyJ3cvHLMDkeR43o5p0/ERjklrf6sukKB0gvtHXWFFt7aZi+V J3AkcksHd17xFg+GpUrnCtRkgSzAn2XdUYpD36YVKBNy78azas5n1tsytS4tTziWEF0F EZx77hqsZGMmNBhYfbUCt//cE1rD/TJFLSMFYzOOMY6Puv4B3njKoPV4J+K8tMjYRjDI 8Gxw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=w0z19Xosp9WrJmXtaCGaP3sBuD6osARAJYJyQGivhiw=; b=URinjhBfW2BR7W0lEDGliR6dv+k5MNZTgz3swGdp2XQq8B3+fdv8HyjAssihopBFZo hmzRN5vYWLwUntQplv8GeX6Rl7RhNgbWWcFf+BaVceVsNo9ndoEVrV1fBF7Nui+GZmj8 nFDyReEDNUHmNSzb7Y9P+iTy6o4j4dBWNIbAWTVtbhWwonESMIVv8WvTS2cNxWvfdX6N 3yYAkMbKVyVVEmfRqUvLGQ3Tnx+Tt0yl0ZM3/S3XP5cA2cEVFjG7vU77tTHrSk72VVD9 /a3ujzlINuLk1Y1i4I/cG4tkR1Hy1OgiDodx53EnhFrnybxrP9WqgYnyVZrGdKzoIvH2 Xljg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=fjM35vVZ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id s6si23435168ilu.124.2021.05.18.01.12.45; Tue, 18 May 2021 01:13:07 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=fjM35vVZ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242209AbhEQO7W (ORCPT + 99 others); Mon, 17 May 2021 10:59:22 -0400 Received: from mail.kernel.org ([198.145.29.99]:37904 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242119AbhEQOt4 (ORCPT ); Mon, 17 May 2021 10:49:56 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id AFE4A61982; Mon, 17 May 2021 14:22:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1621261369; bh=91QgC7MIiv9uQYL8R13UppQHMtH9Qp2zETF0Gr2s0rE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=fjM35vVZvuxwwhb+tbBbs6oTycPiK7QkCcMqR8PlrUEXLBakUylpMCt9LsbDGcglA MChqFB14m8KBnu4Fq0cJfVngYQqdzRTv4qG+Q4dDoEXalrEawn3753WH9DVLEKRF3d vKPI9J6eYjJTvlpdiFqBhxRaGd4klhAbZlri7keM= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, kernel test robot , "Gustavo A. R. Silva" , "David S. Miller" , Sasha Levin Subject: [PATCH 5.4 038/141] ethtool: ioctl: Fix out-of-bounds warning in store_link_ksettings_for_user() Date: Mon, 17 May 2021 16:01:30 +0200 Message-Id: <20210517140244.053546386@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210517140242.729269392@linuxfoundation.org> References: <20210517140242.729269392@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 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/core/ethtool.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/net/core/ethtool.c b/net/core/ethtool.c index cd9bc67381b2..76506975d59a 100644 --- a/net/core/ethtool.c +++ b/net/core/ethtool.c @@ -589,7 +589,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