Received: by 2002:a05:6a10:eb17:0:0:0:0 with SMTP id hx23csp1033874pxb; Fri, 3 Sep 2021 21:24:45 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx3FKZxPzniNjfxBKm7Bf7i5ONP44kZJ2lfwT3eJT+Dclsn7u2n7raU7Gnkuhyi1CbmSaMx X-Received: by 2002:a92:c94d:: with SMTP id i13mr1628891ilq.292.1630729485688; Fri, 03 Sep 2021 21:24:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1630729485; cv=none; d=google.com; s=arc-20160816; b=auXXWo452sBQvlfvH3b8JDzeAk7mFKbNvZ2Z4N8pK00wXb+AnSuZ02KA/4yalEJSFK 97YfTyEcNP7N6Zf+TJqPidFeqhf+Ee+t4B+7i/gYT+Bk35KPO4d+PiaotZZYay6A9UAO Ow6ShQFGRGTBo7d2lNbFVmG8LOfPk0oXkw80+wVj3L3N4FV7t5B8mbXRHz7ZpKxpe+JR LB4ERddjwIFMza7Ag2o2GOLEocfgMVD7VVC8pSd7I82DfPQimWWPwc/wDk9o/tr9WF+u O9AF9FmDMwWwbP5otsAVOipFpp3IjfgVj3FBmr9X93hQU3twUQkMhfbHNZqqZeCK91dE r3sg== 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=JsroHwqSqpHGTdfNxA5PLdxrx3L9qSi9QYjP9ozR0Rg=; b=051v60gvstfTEcotV9mWgxPSn5X/Bs3VQ/UXis1y1+q/VtIxrOxZZB3EaC/BqWZ+7J dz63x74bA3PdQT4ppnG4ly8oEyTP885P0nePOBjeerrvM+pILfSoKFObpb6WEK++5z4Y DEYtLXeo9tsk6u1vKBmm5NtvpBU1oTtTyqUWPbEBqDvaUSqmeWM/0z0/Cl3UNyEP77j2 sx3La+IuYmnWXkPypQjr4v6eDbK+VA/TNzzk/zghKIJ56+uepPMAp1ZycBWmMVRIy/Dt yyyC1lbynhDPsoj4q7NL2tRC0sr8AoxdYKIvOkMFG9zrQwtm9XtLxVzdnSYfj/cIKufe khvA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=H+L7ySwq; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id l8si1123070ioj.7.2021.09.03.21.24.34; Fri, 03 Sep 2021 21:24:45 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=H+L7ySwq; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229754AbhIDEKL (ORCPT + 99 others); Sat, 4 Sep 2021 00:10:11 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:50119 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229508AbhIDEKL (ORCPT ); Sat, 4 Sep 2021 00:10:11 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1630728549; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=JsroHwqSqpHGTdfNxA5PLdxrx3L9qSi9QYjP9ozR0Rg=; b=H+L7ySwqzf4OL9LQrWhnLkcSR7OFfR4ok+PmG2D54kSoW/BGoUIUuIDqPvo27SHDQsq+Ur MW7ZOfV83g0EJwDqllMo12Y0hehP/MpVYhnABFvu2EG++gC1MzNM+jpjuyONzBodusU4wy n1s64ySpgVRGEwjIJ42Q57z+leKqhV8= Received: from mail-ot1-f71.google.com (mail-ot1-f71.google.com [209.85.210.71]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-467-bdo4AeNSPFm7QszzjbikIA-1; Sat, 04 Sep 2021 00:09:08 -0400 X-MC-Unique: bdo4AeNSPFm7QszzjbikIA-1 Received: by mail-ot1-f71.google.com with SMTP id x38-20020a05683040a600b0051e1c81337bso648512ott.3 for ; Fri, 03 Sep 2021 21:09:08 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=JsroHwqSqpHGTdfNxA5PLdxrx3L9qSi9QYjP9ozR0Rg=; b=ZLQSWQzfPK8K9tHS/FY+m05PEQw73/lIae8WUMWCf97Zz62yC3g01+fw4rk85htsR+ SgM+I7FrKX72VN+NLAeDr8JQVX05T6Tdw4Lu2HTajcqDZDu7PiGhnK16qj0nhXLCxo+5 Cfuli9hhWI7KNWofdktRsc/vm07nmglNt9JjSiH4h3cX4zsFVUZ+k0C3rpkmMrnWyZXR EbbS6eSduPRUEaf34DpVaAJPu+cQFhFt0Q1VRmt7BW85dj6dyZAF6Ve5NZVAp98fh3/g 0wMtpaAaHOb1Q4T3VI1DKzzNxdhbJ9H/77yR1LHPanfE82r/S1dbWUxUSUvoDcLkQd5r Y/Uw== X-Gm-Message-State: AOAM5311v48/H1O7HKsmPYoqPu2YYTNa5b6zrnYw7JQvK4udT6k5X3ga +VO1ES4D2ZbKCnnRniQhLaOELCjYd/EIkCEXXCcs0kgw5W48DvaEN1OsVTpAryQxuFoblHljFj0 izfJb15VrZ8ku7XeLGe/ZFLjM X-Received: by 2002:aca:2116:: with SMTP id 22mr1480703oiz.170.1630728547335; Fri, 03 Sep 2021 21:09:07 -0700 (PDT) X-Received: by 2002:aca:2116:: with SMTP id 22mr1480685oiz.170.1630728547110; Fri, 03 Sep 2021 21:09:07 -0700 (PDT) Received: from treble ([2600:1700:6e32:6c00::15]) by smtp.gmail.com with ESMTPSA id b25sm293987ooq.6.2021.09.03.21.09.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Sep 2021 21:09:06 -0700 (PDT) Date: Fri, 3 Sep 2021 21:09:03 -0700 From: Josh Poimboeuf To: Kees Cook Cc: Arnd Bergmann , Jessica Yu , Peter Zijlstra , linux-arch@vger.kernel.org, Heiko Carstens , Vasily Gorbik , Christian Borntraeger , Alexander Egorenkov , Sven Schnelle , Ilya Leoshkevich , "Steven Rostedt (VMware)" , Ingo Molnar , Sami Tolvanen , linux-kernel@vger.kernel.org, linux-s390@vger.kernel.org, linux-hardening@vger.kernel.org, Sean Christopherson Subject: Re: [PATCH 3/4] module: Use a list of strings for ro_after_init sections Message-ID: <20210904040903.tgkkoo2x76zpuj62@treble> References: <20210901233757.2571878-1-keescook@chromium.org> <20210901233757.2571878-4-keescook@chromium.org> <20210903064951.to4dhiu7zua7s6dn@treble> <202109030932.1358C4093@keescook> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <202109030932.1358C4093@keescook> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Sep 03, 2021 at 09:38:42AM -0700, Kees Cook wrote: > On Thu, Sep 02, 2021 at 11:49:51PM -0700, Josh Poimboeuf wrote: > > On Wed, Sep 01, 2021 at 04:37:56PM -0700, Kees Cook wrote: > > > Instead of open-coding the section names, use a list for the sections that > > > need to be marked read-only after init. Unfortunately, it seems we can't > > > do normal section merging with scripts/module.lds.S as ld.bfd doesn't > > > correctly update symbol tables. For more details, see commit 6a3193cdd5e5 > > > ("kbuild: lto: Merge module sections if and only if CONFIG_LTO_CLANG > > > is enabled"). > > > > I'm missing what this has to do with section merging. Can you connect > > the dots here, i.e. what sections would we want to merge and how would > > that help here? > > Right, sorry, if ld.bfd didn't have this issue, we could use section > merging in the module.lds.S file the way we do in vmlinux.lds: > > #ifndef RO_AFTER_INIT_DATA > #define RO_AFTER_INIT_DATA \ > . = ALIGN(8); \ > __start_ro_after_init = .; \ > *(.data..ro_after_init) \ > JUMP_TABLE_DATA \ > STATIC_CALL_DATA \ > __end_ro_after_init = .; > #endif > ... > . = ALIGN((align)); \ > .rodata : AT(ADDR(.rodata) - LOAD_OFFSET) { \ > __start_rodata = .; \ > *(.rodata) *(.rodata.*) \ > SCHED_DATA \ > RO_AFTER_INIT_DATA /* Read only after init */ \ > . = ALIGN(8); \ > __start___tracepoints_ptrs = .; \ > KEEP(*(__tracepoints_ptrs)) /* Tracepoints: pointer array */ \ > __stop___tracepoints_ptrs = .; \ > *(__tracepoints_strings)/* Tracepoints: strings */ \ > } \ > > Then jump_table and static_call sections could be collected into a > new section, as the module loader would only need to look for that > single name. Hm, that could be a really nice way to converge things for vmlinux and module linking. After some digging, 6a3193cdd5e5 isn't necessarily a linker bug. It may be some kind of undefined behavior when the section address isn't specified. If you just explicitly set the section address to zero then the "bug" goes away. diff --git a/scripts/module.lds.S b/scripts/module.lds.S index 04c5685c25cf..80b09b7d405c 100644 --- a/scripts/module.lds.S +++ b/scripts/module.lds.S @@ -30,23 +30,22 @@ SECTIONS { __patchable_function_entries : { *(__patchable_function_entries) } -#ifdef CONFIG_LTO_CLANG /* * With CONFIG_LTO_CLANG, LLD always enables -fdata-sections and * -ffunction-sections, which increases the size of the final module. * Merge the split sections in the final binary. */ - .bss : { + .bss 0 : { *(.bss .bss.[0-9a-zA-Z_]*) *(.bss..L*) } - .data : { + .data 0 : { *(.data .data.[0-9a-zA-Z_]*) *(.data..L*) } - .rodata : { + .rodata 0 : { *(.rodata .rodata.[0-9a-zA-Z_]*) *(.rodata..L*) } @@ -55,11 +54,10 @@ SECTIONS { * With CONFIG_CFI_CLANG, we assume __cfi_check is at the beginning * of the .text section, and is aligned to PAGE_SIZE. */ - .text : ALIGN_CFI { + .text 0 : ALIGN_CFI { *(.text.__cfi_check) *(.text .text.[0-9a-zA-Z_]* .text..L.cfi*) } -#endif } /* bring in arch-specific sections */