From patchwork Fri May 12 02:25:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Fangrui Song X-Patchwork-Id: 92931 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp4813830vqo; Thu, 11 May 2023 20:03:28 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6Lm9XkuQz8BsIfQrRj1yEbK58kA5BFS6YpI1VnCfzc9Q/dZCv+a15s5ErQp1czyZ0HovUQ X-Received: by 2002:a17:902:da92:b0:1ac:94b3:3ab4 with SMTP id j18-20020a170902da9200b001ac94b33ab4mr14479720plx.27.1683860608050; Thu, 11 May 2023 20:03:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683860608; cv=none; d=google.com; s=arc-20160816; b=V5AtmTD8wQn/C9X7c2fG5j4OX4qxcIu8Ib07urpm3jDUhsK9A3A8v6Cno016L7Bej8 zYsJDYUPW5asTb6i8jMUT2mcJxuhj8N9FaeCgemXGSN8O2HW+mZ89ECtSFsEwLSKyEup E6DT2p5q9PIX6q4+MBtqIT9PrvzafHJ7YTNPXsr02FO6wQjFvmA43X3w/J9kEpVUITed zbs3qDW5ZyldbFMJ9c+5P/MyEd3QuO1oCy84mlX39zEPOPkKgiQjmaPSuP7Lvl2DNmYO zYEUUBe8jt/vO8SRsfmEyRz4+pzm7fPx+WSQBP11GPVggKsitTC6m16gVTm+tWwvvqna LICQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:message-id:mime-version:date :dkim-signature; bh=dVrdsQc/biAwpt188V4iZWfS19eaXCE07QPOY9kbdyc=; b=LNPy9P/9DtRA/nOrN6c51NWZW4dsmueG2GB1wZHeyafCdc1+G6+Cx18s5yH2H5DljY /2nkdeF2TtTwdnru0Y2hTdpKJ9S8/p1Psyvv3hQ7129Z0ZC3UDJiIKYETSjH9+JQ0KLm lHEyc8MwcaDrXpQ5yytNyiYIN/kztjA+yRzn3ReBZEzhhXtOWgBgL5C6wZPjXhoCFTY6 P5itUTiYVJygUWXGFQHKyik0rlBB3I4sYKfBK53zTWcoaeDoxquW7TvWHEXnKVpg8igv fsmClb9PgeUOQJQm+Wt1qqoWvdSxzY5piSa2BS0vZLnVoVAPMveo7PmMzhGdoI0BEU0l wSOw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=GQ8UVH9I; 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: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id p18-20020a17090ad31200b00246b1a9630csi21722557pju.130.2023.05.11.20.03.15; Thu, 11 May 2023 20:03:28 -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=GQ8UVH9I; 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 S239604AbjELCZk (ORCPT + 99 others); Thu, 11 May 2023 22:25:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33544 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239158AbjELCZj (ORCPT ); Thu, 11 May 2023 22:25:39 -0400 Received: from mail-yb1-xb49.google.com (mail-yb1-xb49.google.com [IPv6:2607:f8b0:4864:20::b49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7ECB359D0 for ; Thu, 11 May 2023 19:25:37 -0700 (PDT) Received: by mail-yb1-xb49.google.com with SMTP id 3f1490d57ef6-ba6939e78a0so10147748276.0 for ; Thu, 11 May 2023 19:25:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1683858336; x=1686450336; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=dVrdsQc/biAwpt188V4iZWfS19eaXCE07QPOY9kbdyc=; b=GQ8UVH9IygDETvgeENJQeoTFRl8IK6C71cn0eEf8SRe+fcNkVbogqZTEV5spZj3AYl QZY1fCTKrPPA3LJqQI2S73wLreGYzUHXWf6jF0T3V0Qu2J4n42ehYtbxn6HfNim8BzQ1 XB9T4j5TtAct937a1GogPDZ/VyvmPySCrq9ascVSC6HrVysL7S+Dup0RfS+TdHzyffYu +BWPKv5kR//I9uGLkkmM1C3DClzHSfgrHLothXTbfzQ5CPksh3m7s891AsCXvqTXm/Y2 A1ieQSQhQR+UsriiFUS5QNIen/0Zzln7A3aNqNaK8dDOFZlLywHR3jGaZiAOcllmGMaW 5X+w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1683858336; x=1686450336; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=dVrdsQc/biAwpt188V4iZWfS19eaXCE07QPOY9kbdyc=; b=Q8S6U8Ljxy8eJo0tqVo6JzgJD/McSSiBTZZpvvgltDMAQ5ZmjyJmbLCoXp8tAGlrvQ k+YxpJNJ0rcdghSJb06rFiiF/ePIwlliHrUSzBaGo9AZP6sTgid9M08pteQwhkB5wK3j GBQpxU/wWFL7E2BmrihYAJ1LRuqhn1Y3+VNfmM3F6w6NozQpg2wOD3sZiTKAjkRUTHF2 fuVhT5u/pMEsu8HGmUZAhlLtj2bSkOhFPtSlkvfYz4xBUPgjjpYog/s23s9icEW5I4Uh SnujS2kGGAdpER1RvQk9n0W0PnuVdNKu51Vlt7mrq7HphvkWJF42XOGciPfLXvHXhyyf EJKg== X-Gm-Message-State: AC+VfDzePwuAnW37aEVexvUFtIr6XEm9BoA/MN6jcXUAh4MTRqZkInwM TmsywJcCz0OEvEC3z3HSbljrES93AJhG X-Received: from meowing-l.c.googlers.com ([fda3:e722:ac3:cc00:24:72f4:c0a8:3eba]) (user=maskray job=sendgmr) by 2002:a05:690c:10c:b0:55c:a5db:869 with SMTP id bd12-20020a05690c010c00b0055ca5db0869mr19325168ywb.4.1683858336753; Thu, 11 May 2023 19:25:36 -0700 (PDT) Date: Fri, 12 May 2023 02:25:28 +0000 Mime-Version: 1.0 Message-ID: <20230512022528.3430327-1-maskray@google.com> Subject: [PATCH] coredump, vmcore: Set p_align to 4 for PT_NOTE From: Fangrui Song To: Alexander Viro , Christian Brauner , Eric Biederman , Kees Cook , Baoquan He , Vivek Goyal , Dave Young , linux-fsdevel@vger.kernel.org, kexec@lists.infradead.org Cc: linux-kernel@vger.kernel.org, Fangrui Song X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED, USER_IN_DEF_DKIM_WL 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1765655821148763862?= X-GMAIL-MSGID: =?utf-8?q?1765655821148763862?= 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 [2]: https://reviews.llvm.org/D150022 --- fs/binfmt_elf.c | 2 +- fs/binfmt_elf_fdpic.c | 2 +- fs/proc/vmcore.c | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c index 1033fbdfdbec..44b4c42ab8e8 100644 --- a/fs/binfmt_elf.c +++ b/fs/binfmt_elf.c @@ -1517,7 +1517,7 @@ static void fill_elf_note_phdr(struct elf_phdr *phdr, int sz, loff_t offset) phdr->p_filesz = sz; phdr->p_memsz = 0; phdr->p_flags = 0; - phdr->p_align = 0; + phdr->p_align = 4; } static void fill_note(struct memelfnote *note, const char *name, int type, diff --git a/fs/binfmt_elf_fdpic.c b/fs/binfmt_elf_fdpic.c index 05a1471d5283..d76ad3d4f676 100644 --- a/fs/binfmt_elf_fdpic.c +++ b/fs/binfmt_elf_fdpic.c @@ -1269,7 +1269,7 @@ static inline void fill_elf_note_phdr(struct elf_phdr *phdr, int sz, loff_t offs phdr->p_filesz = sz; phdr->p_memsz = 0; phdr->p_flags = 0; - phdr->p_align = 0; + phdr->p_align = 4; return; } diff --git a/fs/proc/vmcore.c b/fs/proc/vmcore.c index 03f5963914a1..cb80a7703d58 100644 --- a/fs/proc/vmcore.c +++ b/fs/proc/vmcore.c @@ -877,7 +877,7 @@ static int __init merge_note_headers_elf64(char *elfptr, size_t *elfsz, phdr.p_offset = roundup(note_off, PAGE_SIZE); phdr.p_vaddr = phdr.p_paddr = 0; phdr.p_filesz = phdr.p_memsz = phdr_sz; - phdr.p_align = 0; + phdr.p_align = 4; /* Add merged PT_NOTE program header*/ tmp = elfptr + sizeof(Elf64_Ehdr); @@ -1068,7 +1068,7 @@ static int __init merge_note_headers_elf32(char *elfptr, size_t *elfsz, phdr.p_offset = roundup(note_off, PAGE_SIZE); phdr.p_vaddr = phdr.p_paddr = 0; phdr.p_filesz = phdr.p_memsz = phdr_sz; - phdr.p_align = 0; + phdr.p_align = 4; /* Add merged PT_NOTE program header*/ tmp = elfptr + sizeof(Elf32_Ehdr);