Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp1108929pxu; Wed, 6 Jan 2021 12:30:49 -0800 (PST) X-Google-Smtp-Source: ABdhPJyDD4DXFakbxVxOEjHccPH0C0vWb3Mq2qpGevPzQWgZlrZSgWI3wnISfjKLmWHyKUvozAVR X-Received: by 2002:a17:906:565a:: with SMTP id v26mr4170632ejr.332.1609965049551; Wed, 06 Jan 2021 12:30:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1609965049; cv=none; d=google.com; s=arc-20160816; b=Pi+h5vVKCuw4XxSnPAlU2bBFILM1V/Yc1Ca/ELRnch4XQBsJJ7GQZti+EWaidNszf2 3LokitZFJ7syNxj9kRooMtCf88Cif/yra+b/0Aj2Ed9vs6LHoLidaN+OzEDQDqamaYhk 6lQi6FRnmKovULtgITt3oNTmXgowTcOBbsWcMirsgmc3y/xpQfnZNW4zzf4TrgU+srIZ guG/ylQkvY7sSVAzjifckkYpSPTlHwXF8l5Tmyui55DOJgLA34pcKUgg3XfVI2/yfM1f cAqNUo0xLmpFKwfPEbBlEHEekZaOVJ89ZtUrmG94AUjclqKE3mXX1lEAHBEbGBzjJV00 4CWw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:reply-to:cc:from:to :dkim-signature:date; bh=SEcJEYlogdS7Rm1Ra3IfaXQRRP547iaFsSnUQcDN8PQ=; b=wH+UkYExI+fBsbGqU2K0DfkvgpiLvjUz55HEtFOiqWqYV9lZCeQsZNxE6Dzlv/RNb/ A3EOyU+27MAN/MzpWvnATvmzQKPP2YP7cHFwSLoLzgAj0Zt6haFDRAqoY6UDUz0+JIom SS4m/S1ydfLpD3DW+HPj8+wZcTtrnJxbT4HLtdKIhuaGgKDK9kXH2iQp8kHh169ur7XC OUYxNF1USITmvsj0f1UBBAk/7/dzM/KuTDUq7pBJwKuV8VcsXsSKHQ17G6xMzJ0ue0Vm CxRFEPX3hyqNflUF1l75EpZNpIQ74IYNMbmIcRAjTimLN0P5XbNCXZitXNbhHwJO/kxu 3F8g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@pm.me header.s=protonmail header.b=lNVn8Gye; 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=QUARANTINE sp=QUARANTINE dis=NONE) header.from=pm.me Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id c6si1305157ejr.727.2021.01.06.12.30.25; Wed, 06 Jan 2021 12:30:49 -0800 (PST) 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=@pm.me header.s=protonmail header.b=lNVn8Gye; 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=QUARANTINE sp=QUARANTINE dis=NONE) header.from=pm.me Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727287AbhAFU3d (ORCPT + 99 others); Wed, 6 Jan 2021 15:29:33 -0500 Received: from mail-40131.protonmail.ch ([185.70.40.131]:58202 "EHLO mail-40131.protonmail.ch" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726655AbhAFU3d (ORCPT ); Wed, 6 Jan 2021 15:29:33 -0500 Date: Wed, 06 Jan 2021 20:28:46 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pm.me; s=protonmail; t=1609964930; bh=SEcJEYlogdS7Rm1Ra3IfaXQRRP547iaFsSnUQcDN8PQ=; h=Date:To:From:Cc:Reply-To:Subject:In-Reply-To:References:From; b=lNVn8GyejzywUtXRPJXjXM1HhMAx8VJZpL4SurVQp06rwRg9lnOZIdwtG9QuDLsYU 56/z1w+Y+TWn1rCr7G2D84U20omS2QgOi085OYaecOSRBEAT9UoQEibsKjnTF1dDEF hcHvQwGPCm9uQ0DRsjxwPrZWCAq5X+1iOFXIcHUGcdwF4LlxTNK1SnmBY2B8pL/Byc COhvu4caJkcCuAyHc/J+ksDcpM3sku4gHSS5q782lYrR5JPzhWiPCzDot3T5oCtrSP xqNnQuLH5uvTMPKRefSh/2WCOukEJLZbM1SeawEmEyiCN7mw0zhYExr8KtSbfhb1dW Faub7FhPGZjfg== To: Nathan Chancellor From: Alexander Lobakin Cc: Alexander Lobakin , Thomas Bogendoerfer , Kees Cook , Fangrui Song , Jiaxun Yang , Alex Smith , Ralf Baechle , Markos Chandras , linux-mips@vger.kernel.org, stable@vger.kernel.org, linux-kernel@vger.kernel.org Reply-To: Alexander Lobakin Subject: Re: [PATCH v2 mips-next 3/4] MIPS: vmlinux.lds.S: catch bad .got, .plt and .rel.dyn at link time Message-ID: <20210106202831.33419-1-alobakin@pm.me> In-Reply-To: <20210106200801.31993-3-alobakin@pm.me> References: <20210106200713.31840-1-alobakin@pm.me> <20210106200801.31993-1-alobakin@pm.me> <20210106200801.31993-3-alobakin@pm.me> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-1.2 required=10.0 tests=ALL_TRUSTED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF shortcircuit=no autolearn=disabled version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on mailout.protonmail.ch Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Nathan Chancellor Date: Wed, 6 Jan 2021 13:23:24 -0700 On Wed, Jan 06, 2021 at 08:08:29PM +0000, Alexander Lobakin wrote: >> Catch any symbols placed in .got, .got.plt, .plt, .rel.dyn >> or .rela.dyn and check for these sections to be zero-sized >> at link time. >> >> At least two of them were noticed in real builds: >> >> mips-alpine-linux-musl-ld: warning: orphan section `.rel.dyn' >> from `init/main.o' being placed in section `.rel.dyn' >> >> ld.lld: warning: :(.got) is being placed in '.got' >> >> Adopted from x86/kernel/vmlinux.lds.S. >> >> Reported-by: Nathan Chancellor # .got >> Suggested-by: Fangrui Song # .rel.dyn >> Signed-off-by: Alexander Lobakin >> --- >> arch/mips/kernel/vmlinux.lds.S | 35 ++++++++++++++++++++++++++++++++++ >> 1 file changed, 35 insertions(+) >> >> diff --git a/arch/mips/kernel/vmlinux.lds.S b/arch/mips/kernel/vmlinux.l= ds.S >> index 5d6563970ab2..05eda9d9a7d5 100644 >> --- a/arch/mips/kernel/vmlinux.lds.S >> +++ b/arch/mips/kernel/vmlinux.lds.S >> @@ -227,4 +227,39 @@ SECTIONS >> =09=09*(.pdr) >> =09=09*(.reginfo) >> =09} >> + >> +=09/* >> +=09 * Sections that should stay zero sized, which is safer to >> +=09 * explicitly check instead of blindly discarding. >> +=09 */ >> + >> +=09.got : { >> +=09=09*(.got) >> +=09=09*(.igot.*) >> +=09} >> +=09ASSERT(SIZEOF(.got) =3D=3D 0, "Unexpected GOT entries detected!") > > This assertion does trigger now. > > $ make -skj"$(nproc)" ARCH=3Dmips CROSS_COMPILE=3Dmipsel-linux-gnu- LLVM= =3D1 \ > O=3Dout/mipsel distclean malta_kvm_guest_defconfig all > ... > ld.lld: error: Unexpected GOT entries detected! > ld.lld: error: Unexpected GOT entries detected! > ... Oops. I'll build my kernel with LLVM stack and dig into it deeper tomorrow. >> +=09.got.plt (INFO) : { >> +=09=09*(.got.plt) >> +=09} >> +=09ASSERT(SIZEOF(.got.plt) =3D=3D 0, "Unexpected GOT/PLT entries detect= ed!") >> + >> +=09.plt : { >> +=09=09*(.plt) >> +=09=09*(.plt.*) >> +=09=09*(.iplt) >> +=09} >> +=09ASSERT(SIZEOF(.plt) =3D=3D 0, "Unexpected run-time procedure linkage= s detected!") >> + >> +=09.rel.dyn : { >> +=09=09*(.rel.*) >> +=09=09*(.rel_*) >> +=09} >> +=09ASSERT(SIZEOF(.rel.dyn) =3D=3D 0, "Unexpected run-time relocations (= .rel) detected!") >> + >> +=09.rela.dyn : { >> +=09=09*(.rela.*) >> +=09=09*(.rela_*) >> +=09} >> +=09ASSERT(SIZEOF(.rela.dyn) =3D=3D 0, "Unexpected run-time relocations = (.rela) detected!") >> } >> -- >> 2.30.0 Thanks, Al