Received: by 2002:a05:6358:9144:b0:117:f937:c515 with SMTP id r4csp10776121rwr; Fri, 12 May 2023 12:51:05 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6DrSUGcXDGRdO9e2PLswft18MvI5/5EHu7jYN61NPAexgL3nl/feHq3Lcjeca0RD6goWHt X-Received: by 2002:a05:6a20:a10d:b0:101:4d10:e40a with SMTP id q13-20020a056a20a10d00b001014d10e40amr18694020pzk.12.1683921065490; Fri, 12 May 2023 12:51:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683921065; cv=none; d=google.com; s=arc-20160816; b=S/Ai78ZmA7IEoTf1I5rHq37ZgTEMJLp5rqeToGL7B3yoa1wN/BLjub/A4VStXz5COo XYPKqCp/rJvx7VtT2Xae6iJz934284jCqsOuCkAo2d3Mu4ViquBj1VR6m79vuMEvY99V cbU87xdLmDjYN0jSbruDratFIIXmX7gqtLrSs2/USbYgz8edo4r2rIDP5e5NIokgcGgN TaCRvV48xH5AoAQlqnv6Ha0p+3JCPz+jCaSMwuJMrzMqqfkN2CQoiBrCFr2uO+RB58r+ +C1/En2BApLkv0E10HJVZtMJdh/sXS+tVHtV2fvEuMku0hkJkry1uVpujQ9qzJZeV3x5 m6tQ== 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=LxNeqg6Grq2YNGnd0knd3lPwc/gWH4WprNL3yZRCSlc=; b=ZU4C5axgGmy/JglBvzu+7rvs5ZOUHtcJE0HGJjQ6WEV1HT/ydQsRFmZNPuugxnUkbf fmtIxg7Ox6Snb6YecVPEHDYPv0qLDeGY+ZUQJPdyJTlmX3h7+GKJhtex98ZZE5G+at0V AIPLQ2qeb9rfKCJI3CnbLbhLf0m8BeTaJpnyU067A1z7kd9njKXbDvBuOstm5Vqmq4da 1/0pSsgj1sgZDPBwjBVDwpFx4eGmwtSqojvOHeFQMGNRbmA86323bligYr68ESVUy9z5 rFefNQ1K5LQg/+OxUvc13AtUj4JNCawFAAxht3FFSurYqOgzbPUeoNfrp5nHLkp5rKg6 O7iA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=lp1Oy3Bh; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id s201-20020a632cd2000000b0052cc0c1c39bsi9582079pgs.684.2023.05.12.12.50.51; Fri, 12 May 2023 12:51:05 -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=@google.com header.s=20221208 header.b=lp1Oy3Bh; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239009AbjELSkE (ORCPT + 99 others); Fri, 12 May 2023 14:40:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55138 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238514AbjELSkD (ORCPT ); Fri, 12 May 2023 14:40:03 -0400 Received: from mail-pl1-x630.google.com (mail-pl1-x630.google.com [IPv6:2607:f8b0:4864:20::630]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A2EC31BE1 for ; Fri, 12 May 2023 11:39:52 -0700 (PDT) Received: by mail-pl1-x630.google.com with SMTP id d9443c01a7336-1a950b982d4so533945ad.0 for ; Fri, 12 May 2023 11:39:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1683916792; x=1686508792; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=LxNeqg6Grq2YNGnd0knd3lPwc/gWH4WprNL3yZRCSlc=; b=lp1Oy3BhdQeeC6JznyjC8cBtFOeNbflFpysHr1GQrN0z/RDcUwp19X8dIn53f44vUU H6iorDT8qheOoQg95Fu6GGi2b6yvR5MviYTnbz2V7XHJkGJBV6gsqCJRm3fqOkwHQAnH ShE6LHl4PKFR+g/210rb3bjvWRSlBMjSPomzjrvTXlqYyGud2RYS0DB1w/u6mJAlPq+K olPKd8cPOmPVrMHiWMXqvvY/x/JzSid+UfiuEo/l/PJ/cH5hyaZn+fgCcrSmxUbTqteB 3DhYxfh+iVRcv3HeKAmRSVq6ZPJ0uU4rT9GO5+vLPcvHUBFo1aVN4GSNzLvp6Zs+3ojy s2qA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1683916792; x=1686508792; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=LxNeqg6Grq2YNGnd0knd3lPwc/gWH4WprNL3yZRCSlc=; b=g8OeAZlMTti0XMe/dPJhNYRxqdKQdZrMewkC0TQHZN2BKF8g4IB16ERR1nFtlAytpH xL03Pe3tYZjfPNM+iqQ+6320wKU4jphm4Y2CDXP1cNm5+15b5igDnpS2I5bMsvaZidm7 bvM4ciqpkDR9ke7ZKQKJPA/OQ9CdzRPOh8OdHu15W65wz6skqQwYVdEUPeRnsFE2E1jH Mdj15kmtE/J7lwCdz3bbfHLio/oWpQGdEllz+xRd1U3yaxc78WK1uMKYcubGVQg48Tfm tQizYdW4kAnmhVZPRoZA0RcUREpZ8dJUGmmabLVilqOzP6To4jpEDbOnHUHLS31MxKa2 Q7BA== X-Gm-Message-State: AC+VfDxbren4aRLQ/UsIzIuRvfNvu7fgkNNAtPFTcb+4rv1on7MHaRDA +MmmE0TGVFA9Kps9ZHtKaPm+0Q== X-Received: by 2002:a17:903:1cb:b0:1a6:6a2d:18f0 with SMTP id e11-20020a17090301cb00b001a66a2d18f0mr271059plh.9.1683916791741; Fri, 12 May 2023 11:39:51 -0700 (PDT) Received: from google.com (25.11.145.34.bc.googleusercontent.com. [34.145.11.25]) by smtp.gmail.com with ESMTPSA id q8-20020a170902dac800b001ac618a6d55sm8215718plx.242.2023.05.12.11.39.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 May 2023 11:39:50 -0700 (PDT) Date: Fri, 12 May 2023 18:39:47 +0000 From: Fangrui Song To: Kees Cook Cc: Alexander Viro , Christian Brauner , Eric Biederman , Baoquan He , Vivek Goyal , Dave Young , linux-fsdevel@vger.kernel.org, kexec@lists.infradead.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] coredump, vmcore: Set p_align to 4 for PT_NOTE Message-ID: <20230512183947.jvaslvmuhy7gndix@google.com> References: <20230512022528.3430327-1-maskray@google.com> <202305121126.E5AD334AA3@keescook> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Disposition: inline In-Reply-To: <202305121126.E5AD334AA3@keescook> X-Spam-Status: No, score=-17.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED,USER_IN_DEF_DKIM_WL, USER_IN_DEF_SPF_WL 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 On 2023-05-12, Kees Cook wrote: >On Fri, May 12, 2023 at 02:25:28AM +0000, Fangrui Song wrote: >> Tools like readelf/llvm-readelf use p_align to parse a PT_NOTE program >> header as an array of 4-byte entries or 8-byte entries. Currently, there >> are workarounds[1] in place for Linux to treat p_align==0 as 4. However, >> it would be more appropriate to set the correct alignment so that tools >> do not have to rely on guesswork. FreeBSD coredumps set p_align to 4 as >> well. >> >> [1]: https://sourceware.org/git/?p=binutils-gdb.git;a=commit;h=82ed9683ec099d8205dc499ac84febc975235af6 > >The interesting bit from here is: > > /* NB: Some note sections may have alignment value of 0 or 1. gABI > specifies that notes should be aligned to 4 bytes in 32-bit > objects and to 8 bytes in 64-bit objects. As a Linux extension, > we also support 4 byte alignment in 64-bit objects. If section > alignment is less than 4, we treate alignment as 4 bytes. */ > if (align < 4) > align = 4; > else if (align != 4 && align != 8) > { > warn (_("Corrupt note: alignment %ld, expecting 4 or 8\n"), > (long) align); > return FALSE; > } > >Should Linux use 8 for 64-bit processes to avoid the other special case? > >(And do we need to make some changes to make sure we are actually >aligned?) > >-Kees 64-bit objects should use 8-byte entries and naturally the 8-byte alignment. Unfortunately, many systems including Solaris, *BSD, and Linux use 4-byte entries for SHT_NOTE/PT_NOTE, and changing this will create a large compatibility problem (see tcmalloc that I recently updated[1]) Linux introduced 8-byte alignment note sections (.note.gnu.property) a while ago, so the ecosystem has to deal with notes of mixed alignments. The resolution is to use the note alignment to decide whether it should be parsed as 4-byte entries or 8-byte entries. I think that just setting `p_align = 4` on the kernel side should be good enough:) [1]: https://github.com/google/tcmalloc/commit/c33cb2d8935002f8ba942028a1f0871d075345a1