Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp5028774pxb; Mon, 15 Feb 2021 07:44:24 -0800 (PST) X-Google-Smtp-Source: ABdhPJwcb60Op8pkb17W1j2QBMKqwQUPbhLO2WgUNs+olSlfwmCeIJ+bIdQ1/f3bJlyY4LFIJtFI X-Received: by 2002:a17:906:b84d:: with SMTP id ga13mr15925580ejb.112.1613403864410; Mon, 15 Feb 2021 07:44:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1613403864; cv=none; d=google.com; s=arc-20160816; b=C1lrTlxNFPnqevPvOH7kcINGwjJ8EjMOTK364LhVXpf1rVOAfODIWRLJ4rMxLygjt8 yARZIzgLPsXsRp9/mILxPcMqEoHwocrbXkqTECWfHkeuWzUaFfKrJ1DeyXBHkiIvNNmt AlLOCWgA6kqRcxRh0n2nrC501nMp3GC1YRnrzUi8cXxa3ZOEhYbaU4xO0nCzCNBj4YsF Do3Sfu7iCESxqNQTYtvNy42a6OasXmhdmBIKKw9kOjnMQ80evPsyntN+sWWVRFG+1gRI ORerLznamXOvO7hX8wudmuxvkP9vtBIQiEtZ9vDlcxdaeF117LUgLjSJxlIKiboXdXtI RUUg== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=yOZh65dpagB28N4S29Myp/s4G4wh8Bm0WI5a8KmOxAo=; b=ICGGlTRLJPkIrtHhzEdRZzUUrFdJG8gPDI0WxLOFjIzWoFmAkRn1z2u1FAey4v4gLu apAOwDPR+YpdepqTKjzVW9wNczIqZKpHyaZdTq62S8CXc8uOLGlNH+r8OCVN8LLj7w6y askdvG3/Hv56lQD7CSkagBWTrKBuIX2TmX0XFMdBwoiU8vGIzpwfpqEBkI/d/CmaymOm 3WEVuDikUNn+TRp4IvO/M1tqfJqOKSluMsAFwP+AcNgEv4TL+Bb38+kzh7/C9QB6+JS5 dwSpY02+MjSZt65pylLmLFpeWk6Kde4KACjW0GOFiANxO12XbX8B5xkTxG87cSeTZtES WgjA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=NUlE9Y8s; 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=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id x8si1513433edl.5.2021.02.15.07.44.01; Mon, 15 Feb 2021 07:44:24 -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=@linuxfoundation.org header.s=korg header.b=NUlE9Y8s; 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=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231697AbhBOPnO (ORCPT + 99 others); Mon, 15 Feb 2021 10:43:14 -0500 Received: from mail.kernel.org ([198.145.29.99]:45562 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230364AbhBOPau (ORCPT ); Mon, 15 Feb 2021 10:30:50 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id D21D564E6D; Mon, 15 Feb 2021 15:28:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1613402933; bh=8uz61srI5MpGZlQlk5XsysikPJubFMCHy6yVxUdvUds=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=NUlE9Y8sQ6X7pWq4qt0NAlbMgnIh11XamzRRb0L0krfqk0gu7nufRX3dF+CJzi+t/ 8o5L/ZQbOqzqe/TnQI0XrPwN1x1cpF86bLJ6qsF1gOiv+an8UwFajO6oLM9K6tycKf IZL63SeazC47PQKjWny5f4gBEdBKd5jSzxMMP6+k= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Arnd Bergmann , Kees Cook , Mark Rutland , Sasha Levin Subject: [PATCH 5.4 25/60] lkdtm: dont move ctors to .rodata Date: Mon, 15 Feb 2021 16:27:13 +0100 Message-Id: <20210215152716.160248805@linuxfoundation.org> X-Mailer: git-send-email 2.30.1 In-Reply-To: <20210215152715.401453874@linuxfoundation.org> References: <20210215152715.401453874@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Mark Rutland [ Upstream commit 3f618ab3323407ee4c6a6734a37eb6e9663ebfb9 ] When building with KASAN and LKDTM, clang may implictly generate an asan.module_ctor function in the LKDTM rodata object. The Makefile moves the lkdtm_rodata_do_nothing() function into .rodata by renaming the file's .text section to .rodata, and consequently also moves the ctor function into .rodata, leading to a boot time crash (splat below) when the ctor is invoked by do_ctors(). Let's prevent this by marking the function as noinstr rather than notrace, and renaming the file's .noinstr.text to .rodata. Marking the function as noinstr will prevent tracing and kprobes, and will inhibit any undesireable compiler instrumentation. The ctor function (if any) will be placed in .text and will work correctly. Example splat before this patch is applied: [ 0.916359] Unable to handle kernel execute from non-executable memory at virtual address ffffa0006b60f5ac [ 0.922088] Mem abort info: [ 0.922828] ESR = 0x8600000e [ 0.923635] EC = 0x21: IABT (current EL), IL = 32 bits [ 0.925036] SET = 0, FnV = 0 [ 0.925838] EA = 0, S1PTW = 0 [ 0.926714] swapper pgtable: 4k pages, 48-bit VAs, pgdp=00000000427b3000 [ 0.928489] [ffffa0006b60f5ac] pgd=000000023ffff003, p4d=000000023ffff003, pud=000000023fffe003, pmd=0068000042000f01 [ 0.931330] Internal error: Oops: 8600000e [#1] PREEMPT SMP [ 0.932806] Modules linked in: [ 0.933617] CPU: 0 PID: 1 Comm: swapper/0 Not tainted 5.10.0-rc7 #2 [ 0.935620] Hardware name: linux,dummy-virt (DT) [ 0.936924] pstate: 40400005 (nZcv daif +PAN -UAO -TCO BTYPE=--) [ 0.938609] pc : asan.module_ctor+0x0/0x14 [ 0.939759] lr : do_basic_setup+0x4c/0x70 [ 0.940889] sp : ffff27b600177e30 [ 0.941815] x29: ffff27b600177e30 x28: 0000000000000000 [ 0.943306] x27: 0000000000000000 x26: 0000000000000000 [ 0.944803] x25: 0000000000000000 x24: 0000000000000000 [ 0.946289] x23: 0000000000000001 x22: 0000000000000000 [ 0.947777] x21: ffffa0006bf4a890 x20: ffffa0006befb6c0 [ 0.949271] x19: ffffa0006bef9358 x18: 0000000000000068 [ 0.950756] x17: fffffffffffffff8 x16: 0000000000000000 [ 0.952246] x15: 0000000000000000 x14: 0000000000000000 [ 0.953734] x13: 00000000838a16d5 x12: 0000000000000001 [ 0.955223] x11: ffff94000da74041 x10: dfffa00000000000 [ 0.956715] x9 : 0000000000000000 x8 : ffffa0006b60f5ac [ 0.958199] x7 : f9f9f9f9f9f9f9f9 x6 : 000000000000003f [ 0.959683] x5 : 0000000000000040 x4 : 0000000000000000 [ 0.961178] x3 : ffffa0006bdc15a0 x2 : 0000000000000005 [ 0.962662] x1 : 00000000000000f9 x0 : ffffa0006bef9350 [ 0.964155] Call trace: [ 0.964844] asan.module_ctor+0x0/0x14 [ 0.965895] kernel_init_freeable+0x158/0x198 [ 0.967115] kernel_init+0x14/0x19c [ 0.968104] ret_from_fork+0x10/0x30 [ 0.969110] Code: 00000003 00000000 00000000 00000000 (00000000) [ 0.970815] ---[ end trace b5339784e20d015c ]--- Cc: Arnd Bergmann Cc: Greg Kroah-Hartman Cc: Kees Cook Acked-by: Kees Cook Signed-off-by: Mark Rutland Link: https://lore.kernel.org/r/20201207170533.10738-1-mark.rutland@arm.com Signed-off-by: Greg Kroah-Hartman Signed-off-by: Sasha Levin --- drivers/misc/lkdtm/Makefile | 2 +- drivers/misc/lkdtm/rodata.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/misc/lkdtm/Makefile b/drivers/misc/lkdtm/Makefile index c70b3822013f4..30c8ac24635d4 100644 --- a/drivers/misc/lkdtm/Makefile +++ b/drivers/misc/lkdtm/Makefile @@ -16,7 +16,7 @@ KCOV_INSTRUMENT_rodata.o := n OBJCOPYFLAGS := OBJCOPYFLAGS_rodata_objcopy.o := \ - --rename-section .text=.rodata,alloc,readonly,load + --rename-section .noinstr.text=.rodata,alloc,readonly,load targets += rodata.o rodata_objcopy.o $(obj)/rodata_objcopy.o: $(obj)/rodata.o FORCE $(call if_changed,objcopy) diff --git a/drivers/misc/lkdtm/rodata.c b/drivers/misc/lkdtm/rodata.c index 58d180af72cf0..baacb876d1d94 100644 --- a/drivers/misc/lkdtm/rodata.c +++ b/drivers/misc/lkdtm/rodata.c @@ -5,7 +5,7 @@ */ #include "lkdtm.h" -void notrace lkdtm_rodata_do_nothing(void) +void noinstr lkdtm_rodata_do_nothing(void) { /* Does nothing. We just want an architecture agnostic "return". */ } -- 2.27.0