Message ID | 202309220957.927ADC0586@keescook |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp5825333vqi; Fri, 22 Sep 2023 12:42:31 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEB+p4yy/VBG4/Uyq4ZVMUwNffhtGNiN9dlx7pAIvSk57ffhIGaHTKgkD/nVETzMQY/COHV X-Received: by 2002:a05:6830:1d2:b0:6bf:21d3:2de5 with SMTP id r18-20020a05683001d200b006bf21d32de5mr678072ota.17.1695411750930; Fri, 22 Sep 2023 12:42:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695411750; cv=none; d=google.com; s=arc-20160816; b=XAoBl8uFc/UI9AAWxOSxrZe8grkmiCMxDtcDRxdgmPn7QhP2P9RkGxULP9BArWjtaJ KXsA5/ilqsHRbve3t9F7li/RHDuHSZOXcZaePt20adLJ89L9d/XBAdFXe5TP45EQMDC0 yK4PkWOn1hpSdHdJRi0lYZ/U3H/t2xsQyPfN+lKZhmuw7PDhLCblL51h/5pfk5u1JsS1 SZTaMrB8735tttdZWvXUssTWxr36FlfrdwC68mJriQVtY3TM0XFpUwBUUNJnptt83QGF 8nE6GO9Y6LSp1deS49mYTwwC5JaV/lIw8KykPqJp0n0cL8z31i9Dp2a4L5rlyGiJMV7e uHyA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-disposition:mime-version:message-id :subject:cc:to:from:date:dkim-signature; bh=ZgApR4QKR0jTTIWGbZED9KyQ8+ob7E8gjbpmfglkOS4=; fh=s+AzyW1cR5UyFtbqbMzs/l2LyFDBrc2AepE8GOrHbas=; b=n4QX+RgRB1YH5nzJOA5oBWdIXp5HvDKNyEV0Xv0wTZL9MmuSx6Z69MFMxSfGiNpMOD UxN6UrIIxuKdoeUNUmX58SLti2wlUedjAMJvQtsV4WxPVpZU6IBc6bfKWdQZYTbAKQHh PvfeAq0VkKZ144ZIpAcBYVRKKnuCpJ/x5R+qnI5o1JwQfzhj1weKyrwQli2Ny0AzE5Ge sBhRzXI5PEd538n3xx/am5LsKSIrAS5Q2ErmV/H9SVhoGsKFbW9XsIwXdnhSMyR1Yd+b /j9D4glR7W/wCRpzOKgVS89K7cFaUFECyq0aMrrTRWHL0b9vXi4zYl36QC67Tc+js57c fPyQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=By1U7SEW; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: from agentk.vger.email (agentk.vger.email. [23.128.96.32]) by mx.google.com with ESMTPS id i62-20020a638741000000b0056c2892bfb9si1428557pge.644.2023.09.22.12.42.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Sep 2023 12:42:30 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) client-ip=23.128.96.32; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=By1U7SEW; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id B1F1B823C120; Fri, 22 Sep 2023 09:59:19 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231713AbjIVQ7L (ORCPT <rfc822;pwkd43@gmail.com> + 28 others); Fri, 22 Sep 2023 12:59:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56142 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229538AbjIVQ7J (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Fri, 22 Sep 2023 12:59:09 -0400 Received: from mail-pl1-x634.google.com (mail-pl1-x634.google.com [IPv6:2607:f8b0:4864:20::634]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6A330122 for <linux-kernel@vger.kernel.org>; Fri, 22 Sep 2023 09:59:03 -0700 (PDT) Received: by mail-pl1-x634.google.com with SMTP id d9443c01a7336-1c0c6d4d650so21177315ad.0 for <linux-kernel@vger.kernel.org>; Fri, 22 Sep 2023 09:59:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1695401943; x=1696006743; darn=vger.kernel.org; h=content-disposition:mime-version:message-id:subject:cc:to:from:date :from:to:cc:subject:date:message-id:reply-to; bh=ZgApR4QKR0jTTIWGbZED9KyQ8+ob7E8gjbpmfglkOS4=; b=By1U7SEWbR+JttBpZqs5RCKlg3WBennOyEICh29yud2CTEiewcdgSdWagQ9HSw7wX1 cEKcjGvJnxcT16oU1kK+1j4wVzbMkzLtROj3ZKO3QI6IZ5dCfW9MNNzwIYjR/YX+xNm5 MUHn0MQFKuE08BNWY/K6wW+3S8IIPN5hL33uQ= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695401943; x=1696006743; h=content-disposition:mime-version:message-id:subject:cc:to:from:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=ZgApR4QKR0jTTIWGbZED9KyQ8+ob7E8gjbpmfglkOS4=; b=X9vaagQf5I21pMzYMVv8iDwtddvhmQDGMcsnDsaoD/Tr+GSDeervDfkHc27pS80bvA SBzmW7tVCYbHMRwmGqRWwY9pvAG+Gmh0HN/Z3Q4QDuUqJ3jiH8HyiiTX+RBh4DU9KvOs 6GOI+L6Cn8+APCBt/pENrVRybjIhjv8QwJ5IDFqC1jJN8Bfom8o0UaqAjTK5vZjks71K nVitAOvxGXFGxbFyeUG2jwg84rcmEdrDTi8yjjb8SmptHkVx7oyPKHEHHJphAfNk9JUL J/ptt5G/2HN6o5R7lJ2/n3dDpINMkFoZADo5o4XTGawDmH9Y5cddoDs7fvRLW2u+c4UV o+Mg== X-Gm-Message-State: AOJu0YxyAbxQwrVukuWfoCTg/toF+4lJXfeUUOJ4PXTNfIqKAko+Dur5 /8jeRG7HaPNjq/q+fK6FnNMEyumWU6DNwBsRuIo= X-Received: by 2002:a17:903:2442:b0:1c4:375c:110a with SMTP id l2-20020a170903244200b001c4375c110amr27448pls.19.1695401942810; Fri, 22 Sep 2023 09:59:02 -0700 (PDT) Received: from www.outflux.net (198-0-35-241-static.hfc.comcastbusiness.net. [198.0.35.241]) by smtp.gmail.com with ESMTPSA id j5-20020a170902da8500b001c57aac6e5esm3728308plx.23.2023.09.22.09.59.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Sep 2023 09:59:02 -0700 (PDT) Date: Fri, 22 Sep 2023 09:59:01 -0700 From: Kees Cook <keescook@chromium.org> To: Linus Torvalds <torvalds@linux-foundation.org> Cc: linux-kernel@vger.kernel.org, Alexey Dobriyan <adobriyan@gmail.com>, Kees Cook <keescook@chromium.org> Subject: [GIT PULL] hardening fixes for v6.6-rc3 Message-ID: <202309220957.927ADC0586@keescook> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.vger.email Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (agentk.vger.email [0.0.0.0]); Fri, 22 Sep 2023 09:59:19 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777768072108755017 X-GMAIL-MSGID: 1777768072108755017 |
Series |
[GIT,PULL] hardening fixes for v6.6-rc3
|
|
Pull-request
https://git.kernel.org/pub/scm/linux/kernel/git/kees/linux.git tags/hardening-v6.6-rc3Message
Kees Cook
Sept. 22, 2023, 4:59 p.m. UTC
Hi Linus, Please pull these hardening fixes for v6.6-rc3. These have been in -next for a week now. Thanks! -Kees The following changes since commit 5f536ac6a5a7b67351e4e5ae4f9e1e57d31268e6: LoadPin: Annotate struct dm_verity_loadpin_trusted_root_digest with __counted_by (2023-08-25 16:07:30 -0700) are available in the Git repository at: https://git.kernel.org/pub/scm/linux/kernel/git/kees/linux.git tags/hardening-v6.6-rc3 for you to fetch changes up to 32a4ec211d4164e667d9d0b807fadf02053cd2e9: uapi: stddef.h: Fix __DECLARE_FLEX_ARRAY for C++ (2023-09-13 20:09:49 -0700) ---------------------------------------------------------------- hardening fixes for v6.6-rc3 - Fix UAPI stddef.h to avoid C++-ism (Alexey Dobriyan) - Fix harmless UAPI stddef.h header guard endif (Alexey Dobriyan) ---------------------------------------------------------------- Alexey Dobriyan (2): uapi: stddef.h: Fix header guard location uapi: stddef.h: Fix __DECLARE_FLEX_ARRAY for C++ include/uapi/linux/stddef.h | 7 +++++++ 1 file changed, 7 insertions(+)
Comments
On Fri, 22 Sept 2023 at 09:59, Kees Cook <keescook@chromium.org> wrote: > > - Fix UAPI stddef.h to avoid C++-ism (Alexey Dobriyan) Ugh. Did we really have to make two different versions of that define? Ok, so C++ did something stupid wrt an empty struct. Fine. But I think we could have still shared the same definition by just using the same 'zero-sized array' trick, regardless of any 'empty struct has a size in C++'. IOW, wouldn't this just work universally, without any "two completely different versions" hack? #define __DECLARE_FLEX_ARRAY(TYPE, NAME) \ struct { \ char __empty_ ## NAME[0]; \ TYPE NAME[]; \ } I didn't test. I'm just hating on that '#ifdef __cplusplus'. Linus
The pull request you sent on Fri, 22 Sep 2023 09:59:01 -0700:
> https://git.kernel.org/pub/scm/linux/kernel/git/kees/linux.git tags/hardening-v6.6-rc3
has been merged into torvalds/linux.git:
https://git.kernel.org/torvalds/c/d90b0276af8f25a0b8ae081a30d1b2a61263393b
Thank you!
On Fri, Sep 22, 2023 at 04:55:45PM -0700, Linus Torvalds wrote: > On Fri, 22 Sept 2023 at 09:59, Kees Cook <keescook@chromium.org> wrote: > > > > - Fix UAPI stddef.h to avoid C++-ism (Alexey Dobriyan) > > Ugh. Did we really have to make two different versions of that define? > > Ok, so C++ did something stupid wrt an empty struct. Fine. > > But I think we could have still shared the same definition by just > using the same 'zero-sized array' trick, regardless of any 'empty > struct has a size in C++'. > > IOW, wouldn't this just work universally, without any "two completely > different versions" hack? > > #define __DECLARE_FLEX_ARRAY(TYPE, NAME) \ > struct { \ > char __empty_ ## NAME[0]; \ > TYPE NAME[]; \ > } > > I didn't test. I'm just hating on that '#ifdef __cplusplus'. Yeah, I had same thought[1], but in the end I left it the way Alexey suggested for one decent reason, and one weak reason: 1) As discovered[2] while porting this helper to ACPICA, using a flexible array in a struct like this does not fly with MSVC, so for MSVC ingesting UAPI, having the separate struct is likely more robust. 2) __cplusplus is relatively common in UAPI headers already: $ git grep __cplusplus -- include/uapi | wc -l 58 -Kees [1] https://lore.kernel.org/all/202309151208.C99747375@keescook/ [2] https://github.com/acpica/acpica/pull/837
On Fri, Sep 22, 2023 at 04:55:45PM -0700, Linus Torvalds wrote: > On Fri, 22 Sept 2023 at 09:59, Kees Cook <keescook@chromium.org> wrote: > > > > - Fix UAPI stddef.h to avoid C++-ism (Alexey Dobriyan) > > Ugh. Did we really have to make two different versions of that define? > > Ok, so C++ did something stupid wrt an empty struct. Fine. > > But I think we could have still shared the same definition by just > using the same 'zero-sized array' trick, regardless of any 'empty > struct has a size in C++'. > > IOW, wouldn't this just work universally, without any "two completely > different versions" hack? > > #define __DECLARE_FLEX_ARRAY(TYPE, NAME) \ > struct { \ > char __empty_ ## NAME[0]; \ > TYPE NAME[]; \ > } This doesn't work with g++ :-( #undef __DECLARE_FLEX_ARRAY #define __DECLARE_FLEX_ARRAY(TYPE, NAME) \ struct { \ char __empty_ ## NAME[0]; \ TYPE NAME[]; \ } struct S1 { __DECLARE_FLEX_ARRAY(int, x); }; main.cc:79:35: error: flexible array member ‘S1::<unnamed struct>::x’ in an otherwise empty ‘struct S1’ 79 | __DECLARE_FLEX_ARRAY(int, x);
On Sat, 23 Sept 2023 at 09:53, Alexey Dobriyan <adobriyan@gmail.com> wrote: > > This doesn't work with g++ :-( Whee. So the compiler seems to literally test "is it at offset 0", and refuses to do flex arrays there. Oh well. So flex arrays are just not usable on C++, because the language tries to "protect" us from outselves. What else is new. I suspect it's the same broken reason that empty structs aren't zero-sized - stop the user from being clever. I had hoped that the C++ people had learnt from their mistakes, but no. Happily we don't have to deal with that crud for kernel code. I don't like the #ifdef, but if it's needed... Linus
On Fri, 22 Sept 2023 at 20:49, Kees Cook <keescook@chromium.org> wrote: > > 2) __cplusplus is relatively common in UAPI headers already: > $ git grep __cplusplus -- include/uapi | wc -l > 58 Look a bit closer. Most of those - by far - is for the usual #if defined(__cplusplus) extern "C" { #endif pattern. IOW, it's explicitly not different code, but telling the C++ compiler that "this is C code". So this new #ifdef is an ugly new pattern of "do totally different things for C++". Apparently required, but very ugly nonetheless. Linus
On Sat, Sep 23, 2023 at 11:04:57AM -0700, Linus Torvalds wrote: > On Fri, 22 Sept 2023 at 20:49, Kees Cook <keescook@chromium.org> wrote: > > > > 2) __cplusplus is relatively common in UAPI headers already: > > $ git grep __cplusplus -- include/uapi | wc -l > > 58 > > Look a bit closer. > > Most of those - by far - is for the usual > > #if defined(__cplusplus) > extern "C" { > #endif > > pattern. IOW, it's explicitly not different code, but telling the C++ > compiler that "this is C code". > > So this new #ifdef is an ugly new pattern of "do totally different > things for C++". > > Apparently required, but very ugly nonetheless. Most of those in uapi/ are likely unnecessary: extern "C" means "don't mangle", but kernel doesn't export functions to userspace except vDSO so there is nothing to mangle in the first place.
On Sun, 24 Sept 2023 at 09:58, Alexey Dobriyan <adobriyan@gmail.com> wrote: > > Most of those in uapi/ are likely unnecessary: extern "C" means > "don't mangle", but kernel doesn't export functions to userspace > except vDSO so there is nothing to mangle in the first place. I suspect a lot of it is "this got copied-and-pasted from a source that used it". And even if you don't export, you have to *match* the linkage in case you have the same name. So I suspect that if you have any kind of prototype sharing between user space (that might use C++) and kernel space, and end up with the same helper functions in both cases, and having some header sharing, you end up with that pattern. And you do it just once, and then it spreads by copy-and-paste. And then about a third of the hits seem to be in tools, which is literally user space and probably actually has C and C++ mixing. Another third is the drm uapi files. I didn't even try to look at what the cause there is. But presumably there are common names used in user space vs kernel. And then the last third is random. We do have a few other uses of __cplusplus. Sometimes just "we have a structure member name that the C++ people decided was a magic keyword". So it's not like this new pattern is *completely* new - we've had random "people want to use this header with C++ compilers and that causes random issues" before. The details are different, the cause is similar. Linus