Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp3010659pxj; Mon, 17 May 2021 15:30:36 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw0FV7KD5xyXzpPqf445t1NRvubipvGNpg0CVonakOTA3HUNP5hr5e5vMeTwBDEKVx1v13r X-Received: by 2002:a17:906:79c8:: with SMTP id m8mr2323329ejo.260.1621290635969; Mon, 17 May 2021 15:30:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621290635; cv=none; d=google.com; s=arc-20160816; b=Nuln1PHOqzo8E9d1o8dSfa9YHJCJU42kKvdljWzoHU9CXJzWs4YjN5Sg7RQ6qyb52m ModiJB16Hfa+lkC4qIRtBsYUXanELEWN3Vm4Ni7y+pRMMkzZPDVSrTXjVyX6ZInsD0xQ oyC2uNs78jbUXs7wzFjZwl7rkp25ATa24GYUL/GyvXrSCUUO04ryDOW4FDtfwP1hqul/ 9tFxqGTBiYq3b5+z+Ufsx7JfFIMG+K1Nn1PT8q5HKR3oe/1hlAeNHVp5UioY0yqFnfvE 5a30uvGWwN5lPC03V9j0dawpUx0UjKOpvNmxuj4Rc+z+PeTRYJbmMUoLNcZdMYXp7tKa Oocg== 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=YBlk4+H+tk5u8dr1ObVtj2ScSWFjlJIZ7P4fQeevtho=; b=vDdEb3WjAt3QX1mrV5na0fKMmVH2Ymi/nVNTqi/t7EkGrKfOH/B4TfK4Ff7T+B3/+v TXNuOMLAT5eUTC0VHZbE+F4FhYFpb5I2/qbBKsKJSwmprPWNUPP6gh/4GawjOCeqandQ 1wkEpfUqSFooNfEIAYYg82mHZPX4PqenA3wUT89kgQDFeUG3AxqSDrOxe7x50/7eghYe 4zhrbGrxH/4TYeW2bU2lSOxQRJno+0fqCKxt2ceKmlgailiTQ3hL9U1qL1DER78XG3pk MmFp+PWpZ1oZk7ZQmU7D62ZNQlNB0lDVhTexM8QxtKLWZ+fuG7wFl/c2dcd/e4cicYKx ej7A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=YipkXvx3; 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 le27si15435613ejc.647.2021.05.17.15.30.12; Mon, 17 May 2021 15:30:35 -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=YipkXvx3; 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 S238802AbhEQOOA (ORCPT + 99 others); Mon, 17 May 2021 10:14:00 -0400 Received: from mail.kernel.org ([198.145.29.99]:60286 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238690AbhEQOL7 (ORCPT ); Mon, 17 May 2021 10:11:59 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id E0189613D4; Mon, 17 May 2021 14:07:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1621260478; bh=0FxnTS8m/zJjYrJelCWVmlfLDSTAJ13HGgXco6gqTZ8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=YipkXvx36IwO73Y5U8f4qTlX2/LpAVz614KElOA2dPPF61QPRtR635GSEk2GOGm27 +tTYAtEbSG+3mmXfIBfyZHps8HjhnSzWXJgkPYPv1vIKC7spE/3vJWdCmBFZkg5bkk C6g1H50/RqA6xayQ0gi/XMc3OYWj4tkbKGT8sCqo= 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.12 098/363] ethtool: ioctl: Fix out-of-bounds warning in store_link_ksettings_for_user() Date: Mon, 17 May 2021 15:59:24 +0200 Message-Id: <20210517140305.904253563@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210517140302.508966430@linuxfoundation.org> References: <20210517140302.508966430@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/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