From patchwork Wed Jan 10 13:26:20 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 13516150 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id DE740C4707B for ; Wed, 10 Jan 2024 13:27:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:From:Subject:Message-ID: Mime-Version:Date:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To: References:List-Owner; bh=9wiTBcKqEYjqJKnObe7rhA92UTsvt4ZhWKn2I4fQgCU=; b=xWW BKkXKFD59Vo4/95/GzrFn7YGDEMdrDUPewQuCPUYRcFlPbW7IZYvftTPusZlOYAr870eiWPt25cim bDoCcB0X+dQQLqy0U/IeBYedEue+0ezMa6Mp+Zr+p5zey40Lk0IvJ1MPUE3cxN8uiRDkyDvcmNHFm tabkgft6x+6rB0G3kHhTGLAgtMrs8zlTdygTCzC1muCkzh/v5b6gNvNAkPha936YwsdTqr0v6rehN atbJnOvRMztonIWmRxDDFwzxgnAfd5UHdJlovmNwesYZM3ijvn/EiiAMz6/sjr6/2PkjT5QqW7z6i yFk7ay1kwE+GAHOAo9OA2UYnolocvlg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1rNYbT-00BxhQ-0I; Wed, 10 Jan 2024 13:26:43 +0000 Received: from mail-yw1-x1149.google.com ([2607:f8b0:4864:20::1149]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1rNYbN-00BxfD-2x for linux-arm-kernel@lists.infradead.org; Wed, 10 Jan 2024 13:26:41 +0000 Received: by mail-yw1-x1149.google.com with SMTP id 00721157ae682-5ee22efe5eeso57380467b3.3 for ; Wed, 10 Jan 2024 05:26:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1704893193; x=1705497993; darn=lists.infradead.org; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=e6/JrCT4rV2Sbz3FyrJnwm7aXJtdj16eq23Hkok8vMU=; b=Zjh2RX3NsiszpP9fwrEB6jqNGdWQ5W9C2Fp59CXwht3fwJASCUqQ9Y9HYa562udfiD 4Op3816wI6yvFMlyqz0Z5V3yAZ+zESqt5VVkHSgBGKibla5aRSg/unX/SFKB6mVeupBn VNH82jEYM2xoA49nDLU8jKdFUgFNvlKODyBQG4/zFGeG09s9XJ1XKU29RL9yXg0khxP0 UnYarc6NsvdMfe28YhL6tPXSjNTgva4R16yqNk8vmMnTbKEeNyhkSIEr7ye08KtgI6T9 9HleEaLAo94Kc010yPLD3JAAo9o8vqR/opuwL0RSM39rRcRN5n3RsybLStZtzoi3321b Y1WQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704893193; x=1705497993; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=e6/JrCT4rV2Sbz3FyrJnwm7aXJtdj16eq23Hkok8vMU=; b=LE9RQ/awbeZKzyuuyqVu+GFsluvohQxJUDE9FUbouwqcwTE1rFuZM1YfZTHsfLQ1zU cjDc3Jy8ua8lfu9mDVQHHJDKtj2+xttrw2rvFJrg2W8v1O1erjiZvb9F9odv4nvWxaar /0dyzFO48L7VberC6Wsuc17/puxIiQ/kT8vOmNPwi2MlmTO04iWcRygQ13ZnrNI7QSlj Z4NY1WjRTMploHYDWnwxws9eHLHn3G1K+ozQXtrj/DgqwBkalXRpKrWexikq3IIkx2X8 f5GqDQlnOpLr++1ZY2T524sIMFfvkBbr6+pijE2sbluJPNds6Ox3SvdBm+CNLPO8C/xI JFyw== X-Gm-Message-State: AOJu0YxQ5UifuT9Mr8m7vy34Qqlp/1nPlz6fqHDxKFOrIUb/N5jlphyP xwFbFTK1Bqosj68B+D6BBJDFx2px7c4+0PYybBIuSzl0w1oQGwjaBS/f8CT3xzgMeNR+ypJ2OGm qUqAjBECPJC2k+kLzh7uk8Btbb5Lt8nLhF88hnlRpZMmfImxndXp6Or/pFRhz0Jsn25pMQprIIL 9SZKSrSA== X-Google-Smtp-Source: AGHT+IH6aOi174duRnouhoX9zcLxIDoLA9Aun4pdt1nDQ92h7SucqVvZl6DS0htAwSzBK6PGMycYPvLr X-Received: from palermo.c.googlers.com ([fda3:e722:ac3:cc00:28:9cb1:c0a8:118a]) (user=ardb job=sendgmr) by 2002:a25:bfd0:0:b0:dbe:30cd:8fcb with SMTP id q16-20020a25bfd0000000b00dbe30cd8fcbmr25786ybm.0.1704893192945; Wed, 10 Jan 2024 05:26:32 -0800 (PST) Date: Wed, 10 Jan 2024 14:26:20 +0100 Mime-Version: 1.0 X-Developer-Key: i=ardb@kernel.org; a=openpgp; fpr=F43D03328115A198C90016883D200E9CA6329909 X-Developer-Signature: v=1; a=openpgp-sha256; l=1573; i=ardb@kernel.org; h=from:subject; bh=aWY/b6KoyCIVc2+/93mt4IpARLBAN7WpowACaxtoNPA=; b=owGbwMvMwCFmkMcZplerG8N4Wi2JIXXerD9tPX8VxXacXW2sY2kconjQ7H7Wq+hiq5L1P9gT7 sb+svbvKGVhEONgkBVTZBGY/ffdztMTpWqdZ8nCzGFlAhnCwMUpABOJmMvwm0Wk7Or7g/unewTv uz9l5RTWTe9aj+ooJk8Q5X2bXPV13mqG/+mbUxoUL7fumrVpM0txrLjEmnJtvjWB1bLe+edSJIt YWAA= X-Mailer: git-send-email 2.43.0.472.g3155946c3a-goog Message-ID: <20240110132619.258809-2-ardb+git@google.com> Subject: [PATCH] arm64: scs: Work around full LTO issue with dynamic SCS From: Ard Biesheuvel To: linux-arm-kernel@lists.infradead.org Cc: will@kernel.org, mark.rutland@arm.com, keescook@chromium.org, samitolvanen@google.com, Ard Biesheuvel X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240110_052639_916265_C6C3844F X-CRM114-Status: GOOD ( 12.79 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org From: Ard Biesheuvel Full LTO takes the '-mbranch-protection=none' passed to the compiler when generating the dynamic shadow call stack patching code as a hint to stop emitting PAC instructions altogether. (Thin LTO appears unaffected by this) Work around this by stripping unwind tables from the object in question, which should be sufficient to prevent the patching code from attempting to patch itself. Signed-off-by: Ard Biesheuvel Reviewed-by: Kees Cook Reviewed-by: Sami Tolvanen --- arch/arm64/kernel/Makefile | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/arch/arm64/kernel/Makefile b/arch/arm64/kernel/Makefile index d95b3d6b471a..e5d03a7039b4 100644 --- a/arch/arm64/kernel/Makefile +++ b/arch/arm64/kernel/Makefile @@ -73,7 +73,13 @@ obj-$(CONFIG_ARM64_MTE) += mte.o obj-y += vdso-wrap.o obj-$(CONFIG_COMPAT_VDSO) += vdso32-wrap.o obj-$(CONFIG_UNWIND_PATCH_PAC_INTO_SCS) += patch-scs.o -CFLAGS_patch-scs.o += -mbranch-protection=none + +# We need to prevent the SCS patching code from patching itself. Using +# -mbranch-protection=none here to avoid the patchable PAC opcodes from being +# generated triggers an issue with full LTO on Clang, which stops emitting PAC +# instructions altogether. So instead, omit the unwind tables used by the +# patching code, so it will not be able to locate its own PAC instructions. +CFLAGS_patch-scs.o += -fno-asynchronous-unwind-tables -fno-unwind-tables # Force dependency (vdso*-wrap.S includes vdso.so through incbin) $(obj)/vdso-wrap.o: $(obj)/vdso/vdso.so