Received: by 10.223.185.116 with SMTP id b49csp2411347wrg; Mon, 5 Mar 2018 02:20:32 -0800 (PST) X-Google-Smtp-Source: AG47ELv4V5e+GIDpRcqfGuJMh1p55sUPom0pu6rloybqyy1Vp/PbkQyQmhftkbYKET/uw4wv3Ks9 X-Received: by 10.101.93.17 with SMTP id e17mr11824855pgr.281.1520245232048; Mon, 05 Mar 2018 02:20:32 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1520245232; cv=none; d=google.com; s=arc-20160816; b=J1e4FQB/nTbKoRrk5Skh/BhytZWneQ3CF73OF2TCz++h1hyxOnhgZJSYJ1/VG46vdk pUalyZAXsrL5YLslyoxYn1DdrkXbj1Q1otfdhKhdipzV/DQd4DWX8+cTfe1ye/01rkH0 Es2siw3mozop7TDPlq/Qu70NyUIJWC/o7nQlgbUf6FVcUuM0GonNxxvbdkWFRYGul9Gx /8NbXEqSALYG7cnm400iiS52Wh1+FIhXan2vdTtiUfmvZLeSqQbp1nxffe6fO6pzSAau y0GP+NhuCcjE2VysAS0a/aQr3ceTusK+AAkHtjEDI1mCq8TpIJdDywMwIAWok7ilivQl P/Rw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:cc:to:subject :message-id:date:from:references:in-reply-to:mime-version :dkim-signature:dkim-filter:arc-authentication-results; bh=svNnamZ4e7++WbRMEbLIhS9XGzMU9g5NerVRXAksQ5I=; b=ND3hBjeSki1HkyNWQYcpibRmdvDjCQX8rEAyvq4GzmbXCIYERM8LbUCV2AS1mpYe5A iMTDG2dHAXR5OvcFtPAH22SQTTdsj66IOlPrGT5/+QB14/ZLhn8WFM50uVc72M0vDpUj K9Vpl4v2Qyf4Xc60z09inPr+F0kL//qUqUR0RFRLdix2DNjgSOyUqgn1cZ9Kd1fFQ+Zl aC2lXD7TMIXXdrFGCuBm0kkuy38FQPM2wD3SYuq1vpVpDyRr7IIHUDSvvgdXwfEVearL Ow0Q7Zbp/MMztwWDonT2O+09+xt/Oxus0q6pMYJ27z6jH9dFmtERXSRqf24bU0bhCTSu STmA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nifty.com header.s=dec2015msa header.b=11o4V7ES; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e5si8166790pgr.444.2018.03.05.02.20.17; Mon, 05 Mar 2018 02:20:32 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@nifty.com header.s=dec2015msa header.b=11o4V7ES; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933526AbeCEJ25 (ORCPT + 99 others); Mon, 5 Mar 2018 04:28:57 -0500 Received: from conssluserg-03.nifty.com ([210.131.2.82]:42527 "EHLO conssluserg-03.nifty.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933291AbeCEJ2r (ORCPT ); Mon, 5 Mar 2018 04:28:47 -0500 Received: from mail-vk0-f45.google.com (mail-vk0-f45.google.com [209.85.213.45]) (authenticated) by conssluserg-03.nifty.com with ESMTP id w259SQFu025392; Mon, 5 Mar 2018 18:28:26 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conssluserg-03.nifty.com w259SQFu025392 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1520242107; bh=svNnamZ4e7++WbRMEbLIhS9XGzMU9g5NerVRXAksQ5I=; h=In-Reply-To:References:From:Date:Subject:To:Cc:From; b=11o4V7ESykblA4WzirBlj+zmnDjCtKh1sSViK48bMnmKyFuQd3txkw+FbGmi65I9z FPmaI1qHfPAv9ZqMiIGfKPEDDLoQbyEtFm+kN3MLmFhsGgFk7HxlMXANPclpWk9l2Z IIk/9RBx1UWq9+RgpAvxq7djziFRGyFZcqrmYYXJBQLl/fKkl46dc27lA849STUctR KXOK+hFLIAgGL/NSliHS6jEIW32/+RpvJNrQA2xaLw1y2DdE8GfqAkaTo+Qc7siSot S/wHcMcqzLXADspce83x736P2CytVVFFrFPfaS2EmpCqtQS/sisaz92uGZmAsyBACS Gm8FwpZpPTtOA== X-Nifty-SrcIP: [209.85.213.45] Received: by mail-vk0-f45.google.com with SMTP id y127so9328779vky.9; Mon, 05 Mar 2018 01:28:26 -0800 (PST) X-Gm-Message-State: APf1xPDcokplt32v95dbv10cYEHlkE20nTwPKPSUfFepXoJAgntAuFKm C/0lxu0Lk9hm2cMLKolyPXjovt+wGDcUNsOQtz4= X-Received: by 10.31.172.67 with SMTP id v64mr10059720vke.54.1520242105339; Mon, 05 Mar 2018 01:28:25 -0800 (PST) MIME-Version: 1.0 Received: by 10.176.32.138 with HTTP; Mon, 5 Mar 2018 01:27:44 -0800 (PST) In-Reply-To: References: <6be06ce5-87e6-0d9d-55b9-6c70c3578ecf@maciej.szmigiero.name> From: Masahiro Yamada Date: Mon, 5 Mar 2018 18:27:44 +0900 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: RANDSTRUCT structs need linux/compiler_types.h (Was: [nfsd4] potentially hardware breaking regression in 4.14-rc and 4.13.11) To: Linus Torvalds Cc: "Maciej S. Szmigiero" , Kees Cook , Patrick McLean , Emese Revfy , Al Viro , Bruce Fields , "Darrick J. Wong" , Linux Kernel Mailing List , Linux NFS Mailing List , Thorsten Leemhuis , "kernel-hardening@lists.openwall.com" Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Linus, 2018-02-22 7:47 GMT+09:00 Linus Torvalds : > On Wed, Feb 21, 2018 at 2:19 PM, Maciej S. Szmigiero > wrote: >> >> One can see that offsets used to access various members of struct path a= re >> different, and also that the original file from step 3 contains an objec= t >> named "__randomize_layout". > > Whee. > > Thanks for root-causing this issue, and this syntax of ours is clearly > *much* too fragile. > > We actually have similar issues with some of our other attributes, > where out nice "helpful" attribute shorthand can end up being just > silently interpreted as a variable name if they aren't defined in > time. > > For most of our other attributes, it just doesn't matter all that much > if some user doesn't happen to see the attribute. For > __randomize_layout, it's obviously very fatal, and silently just > generates crazy code. > > I'm not entirely sure what the right solution is, because it's > obviously much too easy to miss some #include by mistake. It's easy to > say "you should always include the proper header", but if a failure to > do so doesn't end up with any warnings or errors, but just silent bad > code generation, it's much too fragile. > > I wonder if we could change the syntax of that "__randomize_layout" > thing. Some of our related helper macros (ie > randomized_struct_fields_start/end) don't have the same problem, > because if you don't have the define for them, the compiler will > complain about bad syntax. > > And other attribute specifiers we encourage people to put in other > parts of the type, like __user etc, so they don't have that same > parsing issue. > > I guess one _extreme_ fix for this would be to put > > extern struct nostruct __randomize_layout; > > in our include/linux/kconfig.h, which I think we end up always > including first thanks to having it on the command line. > > Because if you do that, you actually get an error: > > CC [M] fs/nfsd/nfs4xdr.o > In file included from ./include/linux/fs_struct.h:5:0, > from fs/nfsd/nfs4xdr.c:36: > ./include/linux/path.h:11:3: error: conflicting types for =E2=80=98__ra= ndomize_layout=E2=80=99 > } __randomize_layout; > ^~~~~~~~~~~~~~~~~~ > In file included from :0:0: > ././include/linux/kconfig.h:8:28: note: previous declaration of > =E2=80=98__randomize_layout=E2=80=99 was here > extern struct nostruct __randomize_layout; > ^~~~~~~~~~~~~~~~~~ > make[1]: *** [scripts/Makefile.build:317: fs/nfsd/nfs4xdr.o] Error 1 > > and we would have figured this out immediately. > > Broken example patch appended, in case somebody wants to play with > something like this or comes up with a better model entirely.. > > Linus > Sorry for chiming in late. I noticed this thread today, honestly, the commit made me upset. Can I suggest another way to make it less fragile? __attribute((...)) can be placed after 'struct'. So, we can write: struct __randomize_layout path { struct vfsmount *mnt; struct dentry *dentry; }; instead of struct path { struct vfsmount *mnt; struct dentry *dentry; } __randomize_layout; If we force the former notation, the undefined __randomize_layout results in a build error instead of silent broken code generation. It is true somebody can still place __randomize_layout after the closing brace, but can we check this by coccicheck or checkpatch.pl? (we can describe it in coding style documentation, of course) IMHO, we should not (ab)use include/linux/kconfig.h to bring in misc things. --=20 Best Regards Masahiro Yamada