From patchwork Wed Feb 21 22:47:44 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Linus Torvalds X-Patchwork-Id: 10234235 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 1AD54602A0 for ; Wed, 21 Feb 2018 22:48:01 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0E40027F93 for ; Wed, 21 Feb 2018 22:48:01 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 02AB927FA3; Wed, 21 Feb 2018 22:48:00 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.2 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from mother.openwall.net (mother.openwall.net [195.42.179.200]) by mail.wl.linuxfoundation.org (Postfix) with SMTP id F112227F97 for ; Wed, 21 Feb 2018 22:47:59 +0000 (UTC) Received: (qmail 31843 invoked by uid 550); 21 Feb 2018 22:47:58 -0000 Mailing-List: contact kernel-hardening-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Delivered-To: mailing list kernel-hardening@lists.openwall.com Received: (qmail 31821 invoked from network); 21 Feb 2018 22:47:57 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:sender:in-reply-to:references:from:date:message-id :subject:to:cc:content-transfer-encoding; bh=1PZcvfUajswGpVWPSiVtIZHjBVvuJujtPvjGby0/8So=; b=DoNBnQ3cjPICacrmRf4zqFtk8I5jY2ipxGMrC8jd0t+MQOC6EdHC4nL332umhGwjNO Kkqh/o9NhO6qqi6dn+tA89fBE+EuA58F6FAqkIxihLwC2Otg112AFUyudVscfGrAYJ6q XWhqM+mNZLoSulxBqa2cT+4LW0eMVvJuc+EmfmS2NCSYD2adepLHX+QsGSbg8HFKrJv4 67O/lNfqQykA1mjPkWuobckEX9yNprECx194bN6BQNm4i7a4dC/xfIhcAZBtJ0sKFQ53 ejBvSClOdKOcndkIO46rOUJkQXC2mEs6YrXsRW0xsmFkLMCVivqBDSiAG9AnMEhiCd01 BfXg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:sender:in-reply-to:references:from :date:message-id:subject:to:cc:content-transfer-encoding; bh=1PZcvfUajswGpVWPSiVtIZHjBVvuJujtPvjGby0/8So=; b=SJzUMvEbnPZ8eIt+mjOIEU9XT7V/OI8oDuXQLCnQdQ+uj/BVTBQoGkPo5O1C8JNL04 eLzY1oz2xRUJj64sRrO6cymzLTN9xKMQX7W8huv9zbKtckSx4cLtil4oaKXycj6qjtej l1+vhM+S7wsW4dH2mbhWmZgHKyp4A+Y7hEYiW7KZFw7NrgMGEdCQxqquebTk06B4Pfqs snpaRnG9ak7FnqVgCVfxWcKJGpW8EZYgEi9ie9m00tnEhdhn/+tra0tcTBHCMTN14NpU 4zVVGLQOgN6LFRtYgM3gDSwBxXSkCZgYpcyb6NIG9VB23y8gN99fwdDc9YTeb66VWvBj 9uhA== X-Gm-Message-State: APf1xPBZdaZkTOkOn5QPEFT7/dcfW32yHI643Uj33dw0g1da8ny9sbjo WCUPNtON8y2LfZ1GrezsGxRfd1RbrutS7YzvCPk= X-Google-Smtp-Source: AH8x225zUJ+aFPIalQaIDm7922Cbog43sD8PgQq+JWrlWRRfKqIAtYYo3S52opQsWgQNUsUWdC+8t7CB4or8rQKmek8= X-Received: by 10.107.12.213 with SMTP id 82mr6222314iom.48.1519253264900; Wed, 21 Feb 2018 14:47:44 -0800 (PST) MIME-Version: 1.0 Sender: linus971@gmail.com In-Reply-To: <6be06ce5-87e6-0d9d-55b9-6c70c3578ecf@maciej.szmigiero.name> References: <6be06ce5-87e6-0d9d-55b9-6c70c3578ecf@maciej.szmigiero.name> From: Linus Torvalds Date: Wed, 21 Feb 2018 14:47:44 -0800 X-Google-Sender-Auth: zCp95De_eVCC1yv8AhW6v_B20fI 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: "Maciej S. Szmigiero" Cc: 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" X-Virus-Scanned: ClamAV using ClamSMTP 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 are > different, and also that the original file from step 3 contains an object > 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 ‘__randomize_layout’ } __randomize_layout; ^~~~~~~~~~~~~~~~~~ In file included from :0:0: ././include/linux/kconfig.h:8:28: note: previous declaration of ‘__randomize_layout’ 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 diff --git a/include/linux/kconfig.h b/include/linux/kconfig.h index fec5076eda91..537dacb83380 100644 --- a/include/linux/kconfig.h +++ b/include/linux/kconfig.h @@ -4,6 +4,10 @@ #include +#ifndef __ASSEMBLY__ + extern struct nostruct __randomize_layout; +#endif + #define __ARG_PLACEHOLDER_1 0, #define __take_second_arg(__ignored, val, ...) val