Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp1797781pxb; Thu, 16 Sep 2021 16:10:57 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzMA5B785STFosP5V9ojFnTAui2/Z62UuA3Nr22bPh8m2G20+/r87KjQsrOUD30Wbeg6d1w X-Received: by 2002:a5e:da08:: with SMTP id x8mr6230344ioj.58.1631833857302; Thu, 16 Sep 2021 16:10:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1631833857; cv=none; d=google.com; s=arc-20160816; b=nIg6AxlnCOiTVUcpaAMTFdXnCiVEnN3p3E6pAKxARpmUWRavIynZ6Q044vPcRFbINQ mVHpMGhI70OdAXp3ZgT02uLe2EcULbqZnjgLklGEFg2FBpKeDrQwg2NbhGPNMsDFHOhm i0FtIkOKvFEirafWphTyb7clgtN7rR4MlCo7wPR2U2gvS4iD74dUMGbx48Cwb0mCr+3g q/trd6O92OdXTExaAR0gXT0WdogTBfixe0LoxlMDDMWh4+5mWgGgWEicbKghUTW91sHm GXEeYscni6ai4Kj2XS9Txla1/Jxy8Xc3wOQ9/MTasssE2k3YaEI6Z64RxHV6/15yRlox T1Cw== 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=FzJnd3fNd0+3lZKe6/cfYbNCl4xUTi15gsL9AP/DH5c=; b=v+MKJnO/mLsk7pqDt4gRR4YjT1j9voVb0AOODjPazBfwXlWJHkH2y+Fh7R9hYMBIe1 aE0OXtlGqoTGZuedNKBBbhDl54RuOBdCtjisu6y+PsjRlJyrTzkh7imvbIVquy6MMljY 5w+WHF6x/J9goY6MVCvOPPij0moWyZYQr2xp3QCh6oymzh5eXN2hAY/9M0HyJ33IEvH1 AA4WuDT0G38MYtRxdWGREDBDg/vUyonkqazlg5w5d6v/8SqFsUHwJtjD0gZZ9q4iLTeN pYG5CwGJgQYyWj0/3kC/EpmwOJ3X4V96eYuoGWX5DPs/RuoFITsee6OQ692OUPFXcWgj kPNQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=uQHmcJVk; 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 o20si4631571iov.71.2021.09.16.16.10.46; Thu, 16 Sep 2021 16:10:57 -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=uQHmcJVk; 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 S1345414AbhIPQuL (ORCPT + 99 others); Thu, 16 Sep 2021 12:50:11 -0400 Received: from mail.kernel.org ([198.145.29.99]:58604 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344419AbhIPQpS (ORCPT ); Thu, 16 Sep 2021 12:45:18 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id A110361A62; Thu, 16 Sep 2021 16:26:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1631809561; bh=SRdQCPEwZvVgjGZFCEs93cZmMKILet+Vok/yBQz6qTg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=uQHmcJVkPHqeozCMWRZ1frCULMFVmJsROS8ZhOrRHsHczljMowx8k9odpiCBDovTN yoRvPU9ToPzcVmlqgNjWZuLpu9IeMnGmswjgJF/Wf2Q5NsG5TV07lSIwCvzzpv+hUf C5gvkENH4dgTIwrxMJSq4AVqycgsfWepxsP8smtA= 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.13 199/380] ipv4: ip_output.c: Fix out-of-bounds warning in ip_copy_addrs() Date: Thu, 16 Sep 2021 17:59:16 +0200 Message-Id: <20210916155810.841083279@linuxfoundation.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210916155803.966362085@linuxfoundation.org> References: <20210916155803.966362085@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 6321c7acb82872ef6576c520b0e178eaad3a25c0 ] Fix the following out-of-bounds warning: In function 'ip_copy_addrs', inlined from '__ip_queue_xmit' at net/ipv4/ip_output.c:517:2: net/ipv4/ip_output.c:449:2: warning: 'memcpy' offset [40, 43] from the object at 'fl' is out of the bounds of referenced subobject 'saddr' with type 'unsigned int' at offset 36 [-Warray-bounds] 449 | memcpy(&iph->saddr, &fl4->saddr, | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 450 | sizeof(fl4->saddr) + sizeof(fl4->daddr)); | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ The problem is that the original code is trying to copy data into a couple of struct members adjacent to each other in a single call to memcpy(). This causes a legitimate compiler warning because memcpy() overruns the length of &iph->saddr and &fl4->saddr. As these are just a couple of struct members, fix this by using direct assignments, instead of memcpy(). 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 Link: https://lore.kernel.org/lkml/d5ae2e65-1f18-2577-246f-bada7eee6ccd@intel.com/ Signed-off-by: Gustavo A. R. Silva Signed-off-by: David S. Miller Signed-off-by: Sasha Levin --- net/ipv4/ip_output.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/net/ipv4/ip_output.c b/net/ipv4/ip_output.c index 8d8a8da3ae7e..a202dcec0dc2 100644 --- a/net/ipv4/ip_output.c +++ b/net/ipv4/ip_output.c @@ -446,8 +446,9 @@ static void ip_copy_addrs(struct iphdr *iph, const struct flowi4 *fl4) { BUILD_BUG_ON(offsetof(typeof(*fl4), daddr) != offsetof(typeof(*fl4), saddr) + sizeof(fl4->saddr)); - memcpy(&iph->saddr, &fl4->saddr, - sizeof(fl4->saddr) + sizeof(fl4->daddr)); + + iph->saddr = fl4->saddr; + iph->daddr = fl4->daddr; } /* Note: skb->sk can be different from sk, in case of tunnels */ -- 2.30.2