Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp2430542iob; Fri, 20 May 2022 09:10:51 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx/szd7wBnQzjm72b8/zAu2KqxrpboZbkg1dhxG/1xWDLVWlUFZRAGNwkq3TKxEV9jFoBUM X-Received: by 2002:a63:81c1:0:b0:3c2:4706:f62b with SMTP id t184-20020a6381c1000000b003c24706f62bmr2880582pgd.11.1653063051039; Fri, 20 May 2022 09:10:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1653063051; cv=none; d=google.com; s=arc-20160816; b=EhA/Ksho/bBBSnEcb5dq1p/vO1h6Gt093Y+GNwmbNXQ/MXjPNbR75Cnv7fwZvjJJYd XBkGnTL/b9XZo5WdiLGuZdPZBfniy8k+hSeiIF/e7U1+9Br+GbiR610HcOyP95f/fJKR FpyV/zFdbZ/STLgdlg6Bo8SvwPHRt8rRCk8cZbyqjaIwPcf+aO/7Rs41IJbTEbHKb83U ceVFpGU0zifz6remq6f7ZoDnAXdZf8MPUIHvW00GUZuV9WDNJlsWPCrB9CJrCFTqZ7er 81usZKDWGdBN+sU4OH/A9uvm4ucOhdgLQ6WxS03bfS04kmfF4PnWjVJ60Mx9oWBQHh41 a86A== 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=y986+ZdOckPzlJLXnwDbvrNORPQJ9hBww73y7LpLMPI=; b=nW3F0Kx8yfIlVXkhoAzSikN57NZ15rSZAes6aXFPiAnW/fPVqmhxr3qJh0vaYzhFpR cwvYXQV6uWBrEn7fB1rqLScV2u8oCV5ch7RFuw9KmEbcvVE89XE+s594DRDIa+GCBxPm v5rIIRINLLj6HidE7GmByCwDeDPxQbX7Sb6EZsnbp16xz8iOevKN6XTgfCM1b271yipk TeZ379MSa7RyByuNskuJq6AiQ8EYY5ldmgvyGMCJVwMp5yMYt9LvITlBuIw/jmF/Cy2O xGMu8gmCHtqbb5TpLQjmX+skHQDBFX9N/b9pwEwPt+hB45FvHG4uvSG/P0bzc/CgsNrK 1NBw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b="cSPr5PM/"; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id y127-20020a633285000000b003f5dca215bfsi11122028pgy.770.2022.05.20.09.10.39; Fri, 20 May 2022 09:10:51 -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=pass header.i=@chromium.org header.s=google header.b="cSPr5PM/"; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239383AbiESOFz (ORCPT + 99 others); Thu, 19 May 2022 10:05:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46078 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239328AbiESOFx (ORCPT ); Thu, 19 May 2022 10:05:53 -0400 Received: from mail-pf1-x436.google.com (mail-pf1-x436.google.com [IPv6:2607:f8b0:4864:20::436]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2C6DA959A for ; Thu, 19 May 2022 07:05:51 -0700 (PDT) Received: by mail-pf1-x436.google.com with SMTP id p12so5298685pfn.0 for ; Thu, 19 May 2022 07:05:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=y986+ZdOckPzlJLXnwDbvrNORPQJ9hBww73y7LpLMPI=; b=cSPr5PM/WyUmap+iM0KLutmdQ44fhG8oUl6rtz2CtZvLyKXw2Ax1ypdwik2OVPGWPZ 9OtYgovB/0k2KitlgP6hokdD/5iVBiCSfEQSo8tVa56jYPRvcUeLABUdvrDyZ+y6HsAb 8PbDL2S1P5jl+66HzLznx2V1z9a2LoxlWKkVY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=y986+ZdOckPzlJLXnwDbvrNORPQJ9hBww73y7LpLMPI=; b=6gLyzbMUY1yFBcjP9l1p2KQqSnyhcg8MftonCNpY0dDwDQ1pYoB2PsPfapiSWeyT2L DHi3JY4fpqWO6+maxGl5VKVAYB3ivWOQyvdd/ebIfyRMlNtnkPKxK32h7xi0R/VfR0Mj wrIBAmV4ib+NLhJVq1gO6HB2OSIFyO44jYW24oFJRfNU2IeDZmubGZRbeqFBzTkxSFoO knKSocxYQjDX/vhQaq/tdRCPvoNqwA7WY5fQlKc5hLvfvCv6t69YV4rkt1frNsJjUM+y g4xrF71Jj7cnrhbRPx5d60VKnRX6ipsyODcM3EfGSi0FN+XdkpE82wwtsZlDbGW44Z/x HqHw== X-Gm-Message-State: AOAM5302xPG/l/5YUphiPqM+JDJ4MgNJI0m9agyW77XX+8kphaPIAfE2 QhY5Q2r4bmyqRb23959bl2G0Eg== X-Received: by 2002:a63:fb02:0:b0:3c1:9513:2e11 with SMTP id o2-20020a63fb02000000b003c195132e11mr4183986pgh.258.1652969150525; Thu, 19 May 2022 07:05:50 -0700 (PDT) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id h7-20020a170902680700b0015e8d4eb2afsm3855534plk.249.2022.05.19.07.05.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 May 2022 07:05:49 -0700 (PDT) Date: Thu, 19 May 2022 07:05:49 -0700 From: Kees Cook To: David Howells Cc: jlayton@kernel.org, Jonathan Corbet , Eric Van Hensbergen , Latchesar Ionkov , Dominique Martinet , Christian Schoenebeck , Marc Dionne , Xiubo Li , Ilya Dryomov , Steve French , William Kucharski , "Matthew Wilcox (Oracle)" , linux-doc@vger.kernel.org, v9fs-developer@lists.sourceforge.net, linux-afs@lists.infradead.org, ceph-devel@vger.kernel.org, linux-cifs@vger.kernel.org, samba-technical@lists.samba.org, linux-fsdevek@vger.kernel.org, linux-hardening@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] netfs: Fix gcc-12 warning by embedding vfs inode in netfs_i_context Message-ID: <202205190704.1DC660E5E@keescook> References: <165296786831.3591209.12111293034669289733.stgit@warthog.procyon.org.uk> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <165296786831.3591209.12111293034669289733.stgit@warthog.procyon.org.uk> X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable 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 On Thu, May 19, 2022 at 02:44:28PM +0100, David Howells wrote: > While randstruct was satisfied with using an open-coded "void *" offset > cast for the netfs_i_context <-> inode casting, __builtin_object_size() as > used by FORTIFY_SOURCE was not as easily fooled. This was causing the > following complaint[1] from gcc v12: > > In file included from ./include/linux/string.h:253, > from ./include/linux/ceph/ceph_debug.h:7, > from fs/ceph/inode.c:2: > In function 'fortify_memset_chk', > inlined from 'netfs_i_context_init' at ./include/linux/netfs.h:326:2, > inlined from 'ceph_alloc_inode' at fs/ceph/inode.c:463:2: > ./include/linux/fortify-string.h:242:25: warning: call to '__write_overflow_field' declared with attribute warning: > detected write beyond size of field (1st parameter); maybe use struct_group()? [-Wattribute-warning] > 242 | __write_overflow_field(p_size_field, size); > | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ > > Fix this by embedding a struct inode into struct netfs_i_context (which > should perhaps be renamed to struct netfs_inode). The struct inode > vfs_inode fields are then removed from the 9p, afs, ceph and cifs inode > structs and vfs_inode is then simply changed to "nic.inode" in those > filesystems. > > Most of the changes were done with: > > perl -p -i -e 's/vfs_inode/nic.inode/'g \ > `git grep -l 'vfs_inode' -- fs/{9p,afs,ceph,cifs}/*.[ch]` > > Kees suggested doing it with a pair structure[2] and a special declarator > to insert that into the network filesystem's inode wrapper[3], but I think > it's cleaner to embed it - and then it doesn't matter if struct > randomisation reorders things. > > Fixes: bc899ee1c898 ("netfs: Add a netfs inode context") > Reported-by: Jeff Layton > Signed-off-by: David Howells > cc: Kees Cook > cc: Jonathan Corbet > cc: Eric Van Hensbergen > cc: Latchesar Ionkov > cc: Dominique Martinet > cc: Christian Schoenebeck > cc: Marc Dionne > cc: Xiubo Li > cc: Ilya Dryomov > cc: Steve French > cc: William Kucharski > cc: "Matthew Wilcox (Oracle)" > cc: linux-doc@vger.kernel.org > cc: v9fs-developer@lists.sourceforge.net > cc: linux-afs@lists.infradead.org > cc: ceph-devel@vger.kernel.org > cc: linux-cifs@vger.kernel.org > cc: samba-technical@lists.samba.org > cc: linux-fsdevek@vger.kernel.org > cc: linux-hardening@vger.kernel.org > Link: https://lore.kernel.org/r/d2ad3a3d7bdd794c6efb562d2f2b655fb67756b9.camel@kernel.org/ [1] > Link: https://lore.kernel.org/r/20220517210230.864239-1-keescook@chromium.org/ [2] > Link: https://lore.kernel.org/r/20220518202212.2322058-1-keescook@chromium.org/ [3] Works for me! :) Thanks for building the alternative. Reviewed-by: Kees Cook -Kees -- Kees Cook