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 Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id BC0ADC07E9D for ; Sat, 24 Sep 2022 16:33:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231156AbiIXQdD (ORCPT ); Sat, 24 Sep 2022 12:33:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36014 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230451AbiIXQdC (ORCPT ); Sat, 24 Sep 2022 12:33:02 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E4D9E67440; Sat, 24 Sep 2022 09:33:01 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 7C189B80687; Sat, 24 Sep 2022 16:33:00 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D72F3C433C1; Sat, 24 Sep 2022 16:32:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1664037179; bh=eDvZ24I+VwB0DHpkH5Ck7T+J+ic8MD34cgwf6xb0jRM=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=uQeJTf1RYI/ZbQfhH2m/NC/v1SafpCBdOJK8fW7ydFR8PcZLhGsv8P62B4RY2Duh/ mpJiYkCbirm5JDz8zNoU4/Z+YrA5TOTMYIwoJ0LeK3z8PH7Lfbqc3yjlLv6i0FQZ9e 5W15s61HmqFG4oRQjRC5uSZIBGn3/fJzXi3Wb/dzBix/m7OvwqFJXUVKo2hKl3re01 tAyjPZv8x54fiZ85Ui6LN31IXsvCk0zPo9vhGoDbSvTS7HjxGji/vWSTbe8cMaovLl H/NMC0wEgCyvmQCbx5G7UvUCu8+nFyNgIGMuG3OVLCHHcd8eBxksUxdNIPBFnmsWpW f/TN+1cPkApEQ== Date: Sat, 24 Sep 2022 11:32:54 -0500 From: "Gustavo A. R. Silva" To: Kees Cook Cc: Miklos Szeredi , linux-unionfs@vger.kernel.org, syzbot+9d14351a171d0d1c7955@syzkaller.appspotmail.com, linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org Subject: Re: [PATCH] ovl: Use "buf" flexible array for memcpy() destination Message-ID: References: <20220924073315.3593031-1-keescook@chromium.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220924073315.3593031-1-keescook@chromium.org> Precedence: bulk List-ID: X-Mailing-List: linux-unionfs@vger.kernel.org On Sat, Sep 24, 2022 at 12:33:15AM -0700, Kees Cook wrote: > The "buf" flexible array needs to be the memcpy() destination to avoid > false positive run-time warning from the recent FORTIFY_SOURCE > hardening: > > memcpy: detected field-spanning write (size 93) of single field "&fh->fb" at fs/overlayfs/export.c:799 (size 21) > > Cc: Miklos Szeredi > Cc: linux-unionfs@vger.kernel.org > Reported-by: syzbot+9d14351a171d0d1c7955@syzkaller.appspotmail.com > Link: https://lore.kernel.org/all/000000000000763a6c05e95a5985@google.com/ > Signed-off-by: Kees Cook Reviewed-by: Gustavo A. R. Silva Thanks! -- Gustavo > --- > fs/overlayfs/export.c | 2 +- > fs/overlayfs/overlayfs.h | 2 +- > 2 files changed, 2 insertions(+), 2 deletions(-) > > diff --git a/fs/overlayfs/export.c b/fs/overlayfs/export.c > index e065a5b9a442..ac9c3ad04016 100644 > --- a/fs/overlayfs/export.c > +++ b/fs/overlayfs/export.c > @@ -796,7 +796,7 @@ static struct ovl_fh *ovl_fid_to_fh(struct fid *fid, int buflen, int fh_type) > return ERR_PTR(-ENOMEM); > > /* Copy unaligned inner fh into aligned buffer */ > - memcpy(&fh->fb, fid, buflen - OVL_FH_WIRE_OFFSET); > + memcpy(fh->buf, fid, buflen - OVL_FH_WIRE_OFFSET); > return fh; > } > > diff --git a/fs/overlayfs/overlayfs.h b/fs/overlayfs/overlayfs.h > index 87759165d32b..a0e450313ea4 100644 > --- a/fs/overlayfs/overlayfs.h > +++ b/fs/overlayfs/overlayfs.h > @@ -108,7 +108,7 @@ struct ovl_fh { > u8 padding[3]; /* make sure fb.fid is 32bit aligned */ > union { > struct ovl_fb fb; > - u8 buf[0]; > + DECLARE_FLEX_ARRAY(u8, buf); > }; > } __packed; > > -- > 2.34.1 >