Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp125381pxf; Tue, 30 Mar 2021 21:57:47 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx5eZVSCJqF94NlHoOlpGZoTb7IHVHGyAGhZ1iYdf7Tp4fexhzR20bKFb93n6nfuQ2S6WUg X-Received: by 2002:a17:907:1b20:: with SMTP id mp32mr1504406ejc.495.1617166667332; Tue, 30 Mar 2021 21:57:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1617166667; cv=none; d=google.com; s=arc-20160816; b=wHXhnNmRJMnSvOSdhB6ewWwKPUelFVQrlAYgg8aONjjj8taSqkX6+I+50cz/6/VIay gPoJrgjbzyT08hQ0aT6fWy9PZ0rKnZBf+uZUbbHuY4Ynqkhy6ly2ap5DBQZV00J+HI9a 8mUdmselLkf9aFG4NLU3AQ7UaRrINcBjKisDB5wWcSv2o751KudPJGAmhZF2rNKsMMNq IP3G4TXnYLlxTzm02ikIQO6Pb/TBgVYWWfHgfwtMgLd4Me6lbrisI3BdYExWAYvDcgaB o9xOmBwtQ4mGyZb+M7wSgcLCIbvtIdOzqbWLmTB32aVwaUpSF2E1Wj6uWhCAsJzgpN9c YQog== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=wIuJCiHGrink7N+zzFOEwUOD7eV2TDviRurljTUqLgQ=; b=RYHb8tcwUIlL2PL/br8RXGXvdpdw+a36HfMNKXDI46/FeExy7X6Eg1wXZ2qJLEoCaU ZyiSQ183BpI+1e864a3ieAs3zL0KYKqMo5Pp/IHnl7oycL4I0kSJqUZuPhFeu0Q3Zqek b22k1lpZVJyRwWrWEzIrekZuhfotvhczX0ILpdAjZ3M+IpWKkj2W6DaqcTUvXBOXtIDQ yJPb45E51d2Uvpt37OjsHF+f9GY/WIPNFoqIdj47NlolfyGUoWDGK+P2Bk6apibbMyMC Ovf79SrhEAwacsnrYDlN5JO/0nPzM1FHS8R8wUG9dnQ9seVgI/Nu/EYeNWODr1/cw9a2 drZA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=XXtGSFRB; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id bc2si828815edb.263.2021.03.30.21.57.24; Tue, 30 Mar 2021 21:57:47 -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=@infradead.org header.s=casper.20170209 header.b=XXtGSFRB; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229852AbhCaEyd (ORCPT + 99 others); Wed, 31 Mar 2021 00:54:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34302 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231392AbhCaEyR (ORCPT ); Wed, 31 Mar 2021 00:54:17 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7FEAAC061574; Tue, 30 Mar 2021 21:54:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=wIuJCiHGrink7N+zzFOEwUOD7eV2TDviRurljTUqLgQ=; b=XXtGSFRBa/aIKQwnwcdl6QW4FB mukV70lxPNlQctc7MaXB1B6802SYl8YwB/gK9wRAxOA2MfPOpVn6mrxda7ZuYI4oyt6oFqqnhIkb4 udoSn9Hwo2L5GhPO4ThoK5c7B0PRqF9OiQQrT6Mv5Po01SGJmEypYWMwoaC4/yHyogBou/Co97jxS zq5xlw1MgMDxpIItsrpUukR2HYneXhmM9BZieJTDrN3+s7TaZAAr7EdKETctkN79yy9LtMNOlQWDp fdSoyMNSPrmEgfzy9W7FEMXganFuZ9OVGgdQq52x2Pg9qQd609O3UOAMrWKXCYVxkR/bffuXTuEIw Q1dcMB2Q==; Received: from willy by casper.infradead.org with local (Exim 4.94 #2 (Red Hat Linux)) id 1lRSre-0042Yc-03; Wed, 31 Mar 2021 04:54:00 +0000 Date: Wed, 31 Mar 2021 05:53:57 +0100 From: Matthew Wilcox To: Andrew Morton Cc: "Gustavo A. R. Silva" , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org Subject: Re: [PATCH][next] hfsplus: Fix out-of-bounds warnings in __hfsplus_setxattr Message-ID: <20210331045357.GV351017@casper.infradead.org> References: <20210330145226.GA207011@embeddedor> <20210330214320.93600506530f1ab18338b467@linux-foundation.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210330214320.93600506530f1ab18338b467@linux-foundation.org> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Mar 30, 2021 at 09:43:20PM -0700, Andrew Morton wrote: > On Tue, 30 Mar 2021 09:52:26 -0500 "Gustavo A. R. Silva" wrote: > > > Fix the following out-of-bounds warnings by enclosing > > structure members file and finder into new struct info: > > > > fs/hfsplus/xattr.c:300:5: warning: 'memcpy' offset [65, 80] from the object at 'entry' is out of the bounds of referenced subobject 'user_info' with type 'struct DInfo' at offset 48 [-Warray-bounds] > > fs/hfsplus/xattr.c:313:5: warning: 'memcpy' offset [65, 80] from the object at 'entry' is out of the bounds of referenced subobject 'user_info' with type 'struct FInfo' at offset 48 [-Warray-bounds] > > > > Refactor the code by making it more "structured." > > > > Also, this helps with the ongoing efforts to enable -Warray-bounds and > > makes the code clearer and avoid confusing the compiler. > > Confused. What was wrong with the old code? Was this warning > legitimate and if so, why? Or is this patch a workaround for a > compiler shortcoming? The offending line is this: - memcpy(&entry.file.user_info, value, + memcpy(&entry.file.info, value, file_finderinfo_len); what it's trying to do is copy two structs which are adjacent to each other in a single call to memcpy(). gcc legitimately complains that the memcpy to this struct overruns the bounds of the struct. What Gustavo has done here is introduce a new struct that contains the two structs, and now gcc is happy that the memcpy doesn't overrun the length of this containing struct.