Received: by 2002:a05:6358:795:b0:dc:4c66:fc3e with SMTP id n21csp484449rwj; Sat, 29 Oct 2022 06:19:25 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7r5bt7NQt1fXYdMVq4sB0u7BoYJ1FZFHznnNrtlHADDh+wiWqZx6nkoRlg5WMlAuMoyvsS X-Received: by 2002:a17:907:6d8c:b0:7ad:b45c:dd24 with SMTP id sb12-20020a1709076d8c00b007adb45cdd24mr1878389ejc.616.1667049565236; Sat, 29 Oct 2022 06:19:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667049565; cv=none; d=google.com; s=arc-20160816; b=ewK0dInKzDf9/9QuyUrN07RP2rGDf+zpwQjZDq7FXgglmbl58Skz810KnZM3XixPpU lYig2v8hvI02/9G75MtYUZU4iEB9B0DAYqbyFTrkTDlAfHEkc7iymH9c0jbiCQ1mjnzQ k3pPOqPhmCdlCDRyFJ71640ZPIElmog5HtR4LePaEJJrxzctZKZtgXs41m1WBRG2h9MF v0wjMW//BVEQouRrUrSummG3cl0krLyFZ67DcyPASlQ7VMuHIs1VW67mImuOv/T9wFVF jkv4rJRbR45Akz/1w6GjFP6Mb787S5i7+pB8upJ/zkKR87F2pJ2GfPdjfenMrjDm9MeE HBLA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=HNZRQvJ17SI6CZ8q+B6eKT5nfyu7tN4BA1nyGluKsSk=; b=OMd9q50mGHjNb8U0ISEIE8kkG2zdksS5w69D7woKv5g+Ixhe3pxlidAAXGM9A5HNdN wiBfubiec0JJ2Q9UzUUwNRaedNPB7YFHjR8B1xRDy+n0HVS7GyFS9ZjE9Pi8Pr0z7Jff 6aVxZ19qkHdSvAUADz2ys5rJ3nDnn2mWZ+DzZhQWnap96NJUwYkqqdFhaNOJ9rxw1f0B oMY0rSdkozi9ZOe9Q/bFsYogfdNofhwCi0xwq59tUVAGBGWAbVArBW+Nc6nvhSCSS/4l HxqBkEGQ0nJlt5JAgvq6y08Wq+odfsZLN4c4B8NYTWVkL5lutxx7NzMbOpD75mNsY/4U NQ9w== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@treblig.org header.s=bytemarkmx header.b=at9ZpwUA; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ht8-20020a170907608800b0073d8e4e8c77si1482010ejc.1005.2022.10.29.06.19.00; Sat, 29 Oct 2022 06:19:25 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=fail header.i=@treblig.org header.s=bytemarkmx header.b=at9ZpwUA; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229728AbiJ2MsP (ORCPT + 99 others); Sat, 29 Oct 2022 08:48:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33442 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229520AbiJ2MsO (ORCPT ); Sat, 29 Oct 2022 08:48:14 -0400 Received: from mx.treblig.org (mx.treblig.org [46.43.15.161]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 751695D725 for ; Sat, 29 Oct 2022 05:48:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=treblig.org ; s=bytemarkmx; 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:Resent-Date:Resent-From:Resent-Sender:Resent-To: Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe :List-Post:List-Owner:List-Archive; bh=HNZRQvJ17SI6CZ8q+B6eKT5nfyu7tN4BA1nyGluKsSk=; b=at9ZpwUAFCJZPj42nan5X3L1Rr 042sI+2l+PxQf0VrCZlM0HkgpHNuzOIJvdYPdIHkLNGWOQHyJJ09Ta3INYPj8OyWn5Iqd3j8glla6 E6OE/8gEse6QrMXR6uFYbEuvrECEFVrZo3K2Wdnw7BPPQPHB1pJwbSrxJd/Lev3VS0cRYXKnRrRhw /6HD7aBuKNkGsmKo0/erYBEKM/63UXxtP8Md3sOf1QKcye7Cej/AmklzVG7TN8BbkGGAMXg/xCgUG Bbs+lrZVNaPtU0R2e2mU979lCAffZ5znwTZsJ0N2OC0tqhPatx4/cb824e7J2HToX8YrsbpULlKht m9Akmgog==; Received: from dg by mx.treblig.org with local (Exim 4.94.2) (envelope-from ) id 1oolFt-00BWbo-Fu; Sat, 29 Oct 2022 13:48:05 +0100 Date: Sat, 29 Oct 2022 13:48:05 +0100 From: "Dr. David Alan Gilbert" To: Kees Cook Cc: shaggy@kernel.org, jfs-discussion@lists.sourceforge.net, linux-kernel@vger.kernel.org, syzbot+5fc38b2ddbbca7f5c680@syzkaller.appspotmail.com Subject: Re: [PATCH] jfs: Fix fortify moan in symlink Message-ID: References: <20221022203913.264855-1-linux@treblig.org> <202210241021.6E9E1EF65@keescook> <202210281526.B32C79C4@keescook> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline In-Reply-To: <202210281526.B32C79C4@keescook> X-Chocolate: 70 percent or better cocoa solids preferably X-Operating-System: Linux/5.10.0-12-amd64 (x86_64) X-Uptime: 13:47:38 up 231 days, 23:13, 1 user, load average: 0.00, 0.00, 0.00 User-Agent: Mutt/2.0.5 (2021-01-21) X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org * Kees Cook (keescook@chromium.org) wrote: > On Mon, Oct 24, 2022 at 07:49:17PM +0100, Dr. David Alan Gilbert wrote: > > * Kees Cook (keescook@chromium.org) wrote: > > > On Sat, Oct 22, 2022 at 09:39:14PM +0100, linux@treblig.org wrote: > > > > From: "Dr. David Alan Gilbert" > > > > > > > > JFS has in jfs_incore.h: > > > > > > > > /* _inline may overflow into _inline_ea when needed */ > > > > /* _inline_ea may overlay the last part of > > > > * file._xtroot if maxentry = XTROOTINITSLOT > > > > */ > > > > union { > > > > struct { > > > > /* 128: inline symlink */ > > > > unchar _inline[128]; > > > > /* 128: inline extended attr */ > > > > unchar _inline_ea[128]; > > > > }; > > > > unchar _inline_all[256]; > > > > > > > > and currently the symlink code copies into _inline; > > > > if this is larger than 128 bytes it triggers a fortify warning of the > > > > form: > > > > > > > > memcpy: detected field-spanning write (size 132) of single field > > > > "ip->i_link" at fs/jfs/namei.c:950 (size 18446744073709551615) > > > > > > Which compiler are you using for this build? > > > > I think that report was the same on gcc on Fedora 37 and whatever > > syzkaller was running. > > > > > This size report (SIZE_MAX) > > > should be impossible to reach. But also, the size is just wrong -- > > > i_inline is 128 bytes, not SIZE_MAX. So, the detection is working > > > (132 > 128), but the report is broken, and I can't see how... > > > > Yeh, and led me down a blind alley for a while thinking something had > > really managed to screwup the strlen somehow. > > This looks like a GCC bug (going at least back to GCC 10.2)[1], but some > extra care around the macro appears to make it go away, so the reporting > variable doesn't get confused/re-evaluated: Thanks for chasing that; are you also going to file a gcc bug? Dave > diff --git a/include/linux/fortify-string.h b/include/linux/fortify-string.h > index 09a032f6ce6b..9e2d96993c30 100644 > --- a/include/linux/fortify-string.h > +++ b/include/linux/fortify-string.h > @@ -550,13 +550,18 @@ __FORTIFY_INLINE bool fortify_memcpy_chk(__kernel_size_t size, > > #define __fortify_memcpy_chk(p, q, size, p_size, q_size, \ > p_size_field, q_size_field, op) ({ \ > - size_t __fortify_size = (size_t)(size); \ > - WARN_ONCE(fortify_memcpy_chk(__fortify_size, p_size, q_size, \ > - p_size_field, q_size_field, #op), \ > + const size_t __fortify_size = (size_t)(size); \ > + const size_t __p_size = (p_size); \ > + const size_t __q_size = (q_size); \ > + const size_t __p_size_field = (p_size_field); \ > + const size_t __q_size_field = (q_size_field); \ > + WARN_ONCE(fortify_memcpy_chk(__fortify_size, __p_size, \ > + __q_size, __p_size_field, \ > + __q_size_field, #op), \ > #op ": detected field-spanning write (size %zu) of single %s (size %zu)\n", \ > __fortify_size, \ > "field \"" #p "\" at " __FILE__ ":" __stringify(__LINE__), \ > - p_size_field); \ > + __p_size_field); \ > __underlying_##op(p, q, __fortify_size); \ > }) > > > > [1] https://syzkaller.appspot.com/bug?id=23d613df5259b977dac1696bec77f61a85890e3d > > -- > Kees Cook -- -----Open up your eyes, open up your mind, open up your code ------- / Dr. David Alan Gilbert | Running GNU/Linux | Happy \ \ dave @ treblig.org | | In Hex / \ _________________________|_____ http://www.treblig.org |_______/