From nobody Sun Feb 8 18:32:56 2026 Received: from mail-pf1-f196.google.com (mail-pf1-f196.google.com [209.85.210.196]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7B9B52C1A7 for ; Fri, 8 Mar 2024 02:45:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.196 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709865952; cv=none; b=ACV1rKpoNTrKNzwn+v17qz9C9YE3sUMLRp3ZfPzpFsI/0MqiUOlEaxyvFZaqxigG9/CM4fLl6xPW2gENVRyGyLtQMbV+hSqhQf70zdl9u/Z5EIZyWOOMiIllLLz5TepCfmxZ/Lub1GnfSDZVCZ06R7AZx9O8x1kSF87shuPoOiE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709865952; c=relaxed/simple; bh=W5jnX+bgKVpgCXJLnqW/MWwdx7iLA8EDehVPIN+x1PE=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=hb1lL3+o/b1xC3UecAbRri6QDiVmMpTkmW20FdtxnuCQ96dZrTFL1oFwoI+uQgId4qgaMbwz2sLWCiewVq1zDm+D/qv6OE1Cpz/xARu9V4ttq+xPLVroX722TuEzkamBaIRERCuTYOSveVW0cWDlSssnwsMeBvFJ8Pb7Yl41/QA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=bytedance.com; spf=pass smtp.mailfrom=bytedance.com; dkim=pass (2048-bit key) header.d=bytedance.com header.i=@bytedance.com header.b=OTvPK80o; arc=none smtp.client-ip=209.85.210.196 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=bytedance.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bytedance.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bytedance.com header.i=@bytedance.com header.b="OTvPK80o" Received: by mail-pf1-f196.google.com with SMTP id d2e1a72fcca58-6e6277f72d8so1259189b3a.1 for ; Thu, 07 Mar 2024 18:45:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1709865950; x=1710470750; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=g2bZO0fGsdGUR3z5kE6H/Hbx7vevj24u/qPVhihb39I=; b=OTvPK80oNGhj0mq/o+hdmPmmytRwnTsqS7e4aSaf7mjpa2yHJevU5cVz/VpzvPD6jo PbitksuxGdYHQnzw0+K3zhjYu6Hemx8vEueLymAK2GMWbL20UDrXXXUbVPz7hOFiFogg iBFLMn5zThv28PTKzL4H8Ky2kxKRbXRhLDVIMQJDPRfcfZfLUXBj5NNziNiiaXFLIlZ/ jXQFbOde7p86ZvEdXidKGB28zvAYDQoqX2XUhJDJ/+eu7DGvv2+/hNi3sh1d3Dj2rfa8 mQziUiPZ+3Vl7TV9I58XsedOmjobwO/WeKu1VWjijp07TAuyidaBiv+HysT7+f+wBOD1 9heA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709865950; x=1710470750; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=g2bZO0fGsdGUR3z5kE6H/Hbx7vevj24u/qPVhihb39I=; b=BCLuQs0RD3ZH4uwLdZQrDJNRBUZjlU8UojNu9OShRjMxgO6iQ2/bWuMU24wM4PJ/SP uAAZRp1s4IlQ9cNnX0HoEoagu2jiknSTSs7gpu3H/ELfMm5hIdrfFn2wl5Z3Qeehhh4N dah1aDDtqiualJYcl8tOevNSEAAu4jWT6ibZeAPl/fs+esz8JfwnAl5WmN15dX22S+M5 mhECUTXmH2IAqT7kn1iu+G1WwgB6x14+mEZRi/yPfysGV+NyP4BxiqV1A58qKXfo3IOj QYBN5byaf97isX7B2lXMhdiV3ZI/KUZTQqdSwOqntyu+zSrbpW23cOCoITuhrcIsbwa9 TDMA== X-Forwarded-Encrypted: i=1; AJvYcCXmhL6qBKgriKsbZNnY24BD5DNRWBaYs/Fr+xGMI+etXK3T0W658WkBXs4N4GigfrJIpUg+FV/hGg3hkuPVgWLk7o9GaC0E3va7ZVbj X-Gm-Message-State: AOJu0YxIR6hZV6lCX2/nCWyP8rn7wACFCwhNeA88FL+UIQEEWhD7W/2q z07i0Aq5UJQjWOgDCzCaDAGnWamk/OzfHFUNyyxANXXDkk6dPVONLsQ2zZQeNbA= X-Google-Smtp-Source: AGHT+IHfqv2VeQUZO5OpjG/niCqlZWhURb4+gfcYwXm93T3wKXkIC2RK2QhIV8Pp46SWhhYaqMJS9A== X-Received: by 2002:a05:6a20:244f:b0:1a1:7821:d012 with SMTP id t15-20020a056a20244f00b001a17821d012mr2882525pzc.26.1709865949817; Thu, 07 Mar 2024 18:45:49 -0800 (PST) Received: from C02CV19DML87.bytedance.net ([2001:c10:ff04:0:1000:0:1:4]) by smtp.gmail.com with ESMTPSA id q9-20020a170902b10900b001d8a93fa5b1sm15244360plr.131.2024.03.07.18.45.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Mar 2024 18:45:49 -0800 (PST) From: Rui Qi To: bp@alien8.de, mingo@redhat.com, tglx@linutronix.de, hpa@zytor.com, jpoimboe@redhat.com, peterz@infradead.org, mbenes@suse.cz, gregkh@linuxfoundation.org, stable@vger.kernel.org, alexandre.chartre@oracle.com Cc: x86@kernel.org, linux-kernel@vger.kernel.org, yuanzhu@bytedance.com, Rui Qi Subject: [PATCH v3 1/3] objtool: is_fentry_call() crashes if call has no destination Date: Fri, 8 Mar 2024 10:45:16 +0800 Message-Id: <20240308024518.19294-2-qirui.001@bytedance.com> X-Mailer: git-send-email 2.39.2 (Apple Git-143) In-Reply-To: <20240308024518.19294-1-qirui.001@bytedance.com> References: <20240308024518.19294-1-qirui.001@bytedance.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Alexandre Chartre commit 87cf61fe848ca8ddf091548671e168f52e8a718e upstream. Fix is_fentry_call() so that it works if a call has no destination set (call_dest). This needs to be done in order to support intra- function calls. Signed-off-by: Alexandre Chartre Signed-off-by: Peter Zijlstra (Intel) Reviewed-by: Miroslav Benes Acked-by: Josh Poimboeuf Link: https://lkml.kernel.org/r/20200414103618.12657-2-alexandre.chartre@or= acle.com Signed-off-by: Rui Qi --- tools/objtool/check.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/objtool/check.c b/tools/objtool/check.c index dfd67243faac..71a24fd46dbd 100644 --- a/tools/objtool/check.c +++ b/tools/objtool/check.c @@ -1367,7 +1367,7 @@ static int decode_sections(struct objtool_file *file) =20 static bool is_fentry_call(struct instruction *insn) { - if (insn->type =3D=3D INSN_CALL && + if (insn->type =3D=3D INSN_CALL && insn->call_dest && insn->call_dest->type =3D=3D STT_NOTYPE && !strcmp(insn->call_dest->name, "__fentry__")) return true; --=20 2.20.1 From nobody Sun Feb 8 18:32:56 2026 Received: from mail-pg1-f195.google.com (mail-pg1-f195.google.com [209.85.215.195]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E48342C6BA for ; Fri, 8 Mar 2024 02:45:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.195 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709865957; cv=none; b=WYS9+tWlach3BydbyY4A7ceI8W6eLnFl/llhhxakH6UKH6X/gdbrN9z2dcOQm8xZXsWxc6zLDkaY+cncYh1NBKEuVimnIx+74mdJ0SseMkdpWrbXzkwBeaK4TLf9qgH3XBr2/x+P9bKeEWvtl3NLuTr7PNO0m0dib7yHaJ66ozE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709865957; c=relaxed/simple; bh=mz+bosMKw7JEpeaxuTDFds5WFr4SLDM7h7W8b2VLQOo=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=mY2xkWy0zhNqGXNQ3WNh/dox+DpKk+5EEMy9bW3HBNYaNNzVG4R+H4mhlccrcTcE/YTfQFLtdCrWhgFk7oDKKrAvYfF0LSOQo2o1blBOseqAvr3BFFDQmNArXgVm6e9aBACz1Ay+3Yn5tdpt5YkLvGLaBfxB5aGypw/uejmSNSs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=bytedance.com; spf=pass smtp.mailfrom=bytedance.com; dkim=pass (2048-bit key) header.d=bytedance.com header.i=@bytedance.com header.b=YqTuX8z9; arc=none smtp.client-ip=209.85.215.195 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=bytedance.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bytedance.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bytedance.com header.i=@bytedance.com header.b="YqTuX8z9" Received: by mail-pg1-f195.google.com with SMTP id 41be03b00d2f7-5e42b4bbfa4so258113a12.1 for ; Thu, 07 Mar 2024 18:45:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1709865955; x=1710470755; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=wSpDjbqI0gNW8wl9pMQX51obps/WN2ZG0m8/65kcflw=; b=YqTuX8z9xHkFz2QCy8WnaD1vSz7nSPEJ3hX28YF8V4UtzDvNDwJhAe/Le6In7vUnn6 BFMyAOT4HoZyj+Qy7WLSqvMV6wzyxBAdUCFsUCbsUSKlUdQMhzP4FQQ+9QOM/GvUCBkU IbLbFfhlnYo2TBo1h2+qX7KUTT9Yc5Vid9gLIBcT/KSXKJ4LKa4xkF1vg9bMlWPZmr5a F9YZmcSG7BYkUBz1i7jEQ6nNQ+jw78EVVdI7rD6eCE+6Z43MoAXXMDxew9G04QcBjhSr 8fX38cX5GfFCSAlXRJAnYg38Cc/Bpg8DIEeX5mRUQMEgQhE3SxNdvfl8q5xNJLiM3Rvs MAVw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709865955; x=1710470755; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=wSpDjbqI0gNW8wl9pMQX51obps/WN2ZG0m8/65kcflw=; b=IPsM9QYKm3eO0pk9syr9zrl54Cnyb19Vzu2TFtSpyTK5LCNba+5HTf78clq7hpSmw/ +AeecWhTWYrROVTgnsBXHtL6NFdSt39ZFeErrGM/WtJFVseubg9n3vpeAXqd7t/J/13p W8sYlCnZ0V2nCavrOneyO+8s5sqLjizdfmxoiNfXvIXzDYDBIizLRghxw0wY6HbKmgQs ZF3WS9tet23JeQeZ2Qi2cugq4tZleGzL5nr3Yb6T9S4WD+xQk+yUQsU59HA4nMlmhIsv H5Ff12c/rc3S7gWvaLgIO0j4MJ5BDEH26Ok3Z9oKUNU/SWgpy4zB9JuUUx3sKrR4QDn9 m+Vw== X-Forwarded-Encrypted: i=1; AJvYcCU+wabS1z8vyMS4xpxoLoBHtpbTUS2iCtqs0Ox6gBHsYtiyXGXauLfzO6+vgeRUcsIqWFfQeoHFYSHdvHkFAKxtzfKwwQEYWjY9fJcy X-Gm-Message-State: AOJu0YxYaGn924De9CXOn3Su+oLotmsDxKI7+ks9A/JEg1Uz8fV8D3Ux jNjIHtkZoX3C/haBgSk9xEysM/oOnaHIuDbB2ZsUJtcDxuIVRBtvlwFbp7J9zxQ= X-Google-Smtp-Source: AGHT+IFB4r2cubJXEhC25w0CZruD70/PPODADSzF0jy4Q63MjOnCL0Ndt4sjV8zxbalugefbZA+8Sg== X-Received: by 2002:a17:902:bc86:b0:1da:1c72:2ca7 with SMTP id bb6-20020a170902bc8600b001da1c722ca7mr9782633plb.29.1709865955391; Thu, 07 Mar 2024 18:45:55 -0800 (PST) Received: from C02CV19DML87.bytedance.net ([2001:c10:ff04:0:1000:0:1:4]) by smtp.gmail.com with ESMTPSA id q9-20020a170902b10900b001d8a93fa5b1sm15244360plr.131.2024.03.07.18.45.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Mar 2024 18:45:55 -0800 (PST) From: Rui Qi To: bp@alien8.de, mingo@redhat.com, tglx@linutronix.de, hpa@zytor.com, jpoimboe@redhat.com, peterz@infradead.org, mbenes@suse.cz, gregkh@linuxfoundation.org, stable@vger.kernel.org, alexandre.chartre@oracle.com Cc: x86@kernel.org, linux-kernel@vger.kernel.org, yuanzhu@bytedance.com, Rui Qi Subject: [PATCH v3 2/3] objtool: Add support for intra-function calls Date: Fri, 8 Mar 2024 10:45:17 +0800 Message-Id: <20240308024518.19294-3-qirui.001@bytedance.com> X-Mailer: git-send-email 2.39.2 (Apple Git-143) In-Reply-To: <20240308024518.19294-1-qirui.001@bytedance.com> References: <20240308024518.19294-1-qirui.001@bytedance.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Alexandre Chartre commit 8aa8eb2a8f5b3305a95f39957dd2b715fa668e21 upstream. Change objtool to support intra-function calls. On x86, an intra-function call is represented in objtool as a push onto the stack (of the return address), and a jump to the destination address. That way the stack information is correctly updated and the call flow is still accurate. Signed-off-by: Alexandre Chartre Signed-off-by: Peter Zijlstra (Intel) Reviewed-by: Miroslav Benes Acked-by: Josh Poimboeuf Link: https://lkml.kernel.org/r/20200414103618.12657-4-alexandre.chartre@or= acle.com Signed-off-by: Rui Qi --- include/linux/frame.h | 11 ++++ .../Documentation/stack-validation.txt | 8 +++ tools/objtool/arch/x86/decode.c | 6 ++ tools/objtool/check.c | 62 +++++++++++++++++-- 4 files changed, 83 insertions(+), 4 deletions(-) diff --git a/include/linux/frame.h b/include/linux/frame.h index 02d3ca2d9598..303cda600e56 100644 --- a/include/linux/frame.h +++ b/include/linux/frame.h @@ -15,9 +15,20 @@ static void __used __section(.discard.func_stack_frame_non_standard) \ *__func_stack_frame_non_standard_##func =3D func =20 +/* + * This macro indicates that the following intra-function call is valid. + * Any non-annotated intra-function call will cause objtool to issue a war= ning. + */ +#define ANNOTATE_INTRA_FUNCTION_CALL \ + 999: \ + .pushsection .discard.intra_function_calls; \ + .long 999b; \ + .popsection; + #else /* !CONFIG_STACK_VALIDATION */ =20 #define STACK_FRAME_NON_STANDARD(func) +#define ANNOTATE_INTRA_FUNCTION_CALL =20 #endif /* CONFIG_STACK_VALIDATION */ =20 diff --git a/tools/objtool/Documentation/stack-validation.txt b/tools/objto= ol/Documentation/stack-validation.txt index de094670050b..ee26bb382b70 100644 --- a/tools/objtool/Documentation/stack-validation.txt +++ b/tools/objtool/Documentation/stack-validation.txt @@ -290,6 +290,14 @@ they mean, and suggestions for how to fix them. https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D70646 =20 =20 +11. file.o: warning: unannotated intra-function call + + This warning means that a direct call is done to a destination which + is not at the beginning of a function. If this is a legit call, you + can remove this warning by putting the ANNOTATE_INTRA_FUNCTION_CALL + directive right before the call. + + If the error doesn't seem to make sense, it could be a bug in objtool. Feel free to ask the objtool maintainer for help. =20 diff --git a/tools/objtool/arch/x86/decode.c b/tools/objtool/arch/x86/decod= e.c index a62e032863a8..c3ff62c085c8 100644 --- a/tools/objtool/arch/x86/decode.c +++ b/tools/objtool/arch/x86/decode.c @@ -437,6 +437,12 @@ int arch_decode_instruction(struct elf *elf, struct se= ction *sec, =20 case 0xe8: *type =3D INSN_CALL; + /* + * For the impact on the stack, a CALL behaves like + * a PUSH of an immediate value (the return address). + */ + op->src.type =3D OP_SRC_CONST; + op->dest.type =3D OP_DEST_PUSH; break; =20 case 0xfc: diff --git a/tools/objtool/check.c b/tools/objtool/check.c index 71a24fd46dbd..0fa414869f45 100644 --- a/tools/objtool/check.c +++ b/tools/objtool/check.c @@ -645,6 +645,7 @@ static int add_jump_destinations(struct objtool_file *f= ile) return 0; } =20 + /* * Find the destination instructions for all calls. */ @@ -666,10 +667,7 @@ static int add_call_destinations(struct objtool_file *= file) dest_off); =20 if (!insn->call_dest && !insn->ignore) { - WARN_FUNC("unsupported intra-function call", - insn->sec, insn->offset); - if (retpoline) - WARN("If this is a retpoline, please patch it in with alternatives an= d annotate it with ANNOTATE_NOSPEC_ALTERNATIVE."); + WARN_FUNC("unannotated intra-function call", insn->sec, insn->offset); return -1; } =20 @@ -1291,6 +1289,58 @@ static int read_retpoline_hints(struct objtool_file = *file) return 0; } =20 + +static int read_intra_function_calls(struct objtool_file *file) +{ + struct instruction *insn; + struct section *sec; + struct rela *rela; + + sec =3D find_section_by_name(file->elf, ".rela.discard.intra_function_cal= ls"); + if (!sec) + return 0; + + list_for_each_entry(rela, &sec->rela_list, list) { + unsigned long dest_off; + + if (rela->sym->type !=3D STT_SECTION) { + WARN("unexpected relocation symbol type in %s", + sec->name); + return -1; + } + + insn =3D find_insn(file, rela->sym->sec, rela->addend); + if (!insn) { + WARN("bad .discard.intra_function_call entry"); + return -1; + } + + if (insn->type !=3D INSN_CALL) { + WARN_FUNC("intra_function_call not a direct call", + insn->sec, insn->offset); + return -1; + } + + /* + * Treat intra-function CALLs as JMPs, but with a stack_op. + * See add_call_destinations(), which strips stack_ops from + * normal CALLs. + */ + insn->type =3D INSN_JUMP_UNCONDITIONAL; + + dest_off =3D insn->offset + insn->len + insn->immediate; + insn->jump_dest =3D find_insn(file, insn->sec, dest_off); + if (!insn->jump_dest) { + WARN_FUNC("can't find call dest at %s+0x%lx", + insn->sec, insn->offset, + insn->sec->name, dest_off); + return -1; + } + } + + return 0; +} + static void mark_rodata(struct objtool_file *file) { struct section *sec; @@ -1346,6 +1396,10 @@ static int decode_sections(struct objtool_file *file) if (ret) return ret; =20 + ret =3D read_intra_function_calls(file); + if (ret) + return ret; + ret =3D add_call_destinations(file); if (ret) return ret; --=20 2.20.1 From nobody Sun Feb 8 18:32:56 2026 Received: from mail-pl1-f177.google.com (mail-pl1-f177.google.com [209.85.214.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6E8C02D044 for ; Fri, 8 Mar 2024 02:46:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.177 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709865962; cv=none; b=pmFZ1Tyy6yokSsHIqD6k2LXlpNxI1qzcpmUSKqFru5ZjeJQpDzlMS6GsNhltqh8gAuCXTm00Zh4elVZOyxDUU56MTN6AdLJhDen5xl3bXDERNgPkAiJS7cgZeEGxNOVlXXAhyVO4yrNRWUGPf4y68DjZEYpRi1BZQDlowRKvfFI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709865962; c=relaxed/simple; bh=mBf6wZN0cIO/N0wB3JaiYh3xHh0wn1kXf+UEavA0MRI=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=gJQR8OwncnU/fMJlsCsyn+/TKQETv9ju4VRkSqoqmllTM2VNUWGCIjRdvrJInpzavEBzAquTDhlkpamgcC3AJB97tIaUdi3wPaY2XLrb7lm+AHmF+KrpJ7KtF3B9Xkp9s2iHiXxCDoY6pFk9pI2fVAQ4RtumYWg5iuYmYYCqWdU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=bytedance.com; spf=pass smtp.mailfrom=bytedance.com; dkim=pass (2048-bit key) header.d=bytedance.com header.i=@bytedance.com header.b=LYs2U4SY; arc=none smtp.client-ip=209.85.214.177 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=bytedance.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bytedance.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bytedance.com header.i=@bytedance.com header.b="LYs2U4SY" Received: by mail-pl1-f177.google.com with SMTP id d9443c01a7336-1dc139ed11fso19417145ad.0 for ; Thu, 07 Mar 2024 18:46:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1709865961; x=1710470761; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=+ptT0otTY0d8yLPVMZk8S5EDz2pvO8mJ9CtUPG2vMjQ=; b=LYs2U4SYBKlmapChzsUbq6fG7abnk8Nafk/CNlgtXWApONCJAmbnxEME0BT905dSTB EdoHN9kA3Yj7txygENvK6QruG7psv0bI9EmjOrmDuXw2q0RvPh7qP6By/ee0GNlaTbKV trFe/pKo78D7ZuVEm65X0fszYZPvz/OsWZsNFgqJe/worq66JCixVeWOfkyfDvFZL+T+ 6CE/NQtoqMLy1jHqQ9ocMaufx2Q0Ecb7uHfI364S004KGWYCLs3eEllt71RDGVmK9bW1 dySNohvcxEOomTYhcgmXv/6H/M4iq8NONmHiJjz66nDW1ODLM4DMhFKyKSwlnrj0upwP MeEQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709865961; x=1710470761; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=+ptT0otTY0d8yLPVMZk8S5EDz2pvO8mJ9CtUPG2vMjQ=; b=oho+W59ZSKJWCyDnToXmaKOPpdtLZG1sG+aLIIm5+5Xvd+sxNPpiEfxAcF0Yk6/UcX EAFUBJHt0h5pgXkuVWOdeIg4v9Vh2scIzlxu78TLELphIncpM4HOXWNP38XOOY4MUOwb xgHG790ZlWEdpNMBR3SEThGMpTLbF4XIoYdKkZbKBhGUVdt9ptq33WXKkc9hYyfiQY43 8lArL7gi+qBEg85gqiEWgCeVZElEMdkwUnCLvXrrgrpCBMPIoSwTzjMhoq8ZoalK4Vba B/NFHiimTsrFtpGrNyTFzpb8ktPHyUYaI8z+gkaiVy5Wi5lqs5weEi7Yq1IBqUcPtqch iiBQ== X-Forwarded-Encrypted: i=1; AJvYcCWG+TSkRjNZn4KT1n0Fz8D5rr6IJQCBKtiMIO93PsoJsFGBO5Vq7g+tFgi4bPqV2F9uENQ58dQeDWMVsSR+fT/WQdNVQ9Zc5/FzPESn X-Gm-Message-State: AOJu0Yx626x+JLkoYGWxwcYC0OKeFjgs220Y+YTOsLFhhTRpS2oZ79xi 9L2RpWcDnFAYAlo+l8oiit9HviZKQfKKkCT1IVNC0j8c7Ze8JTmKqo4XaSChgMA= X-Google-Smtp-Source: AGHT+IH98yvTHUjCSYM6deOHYjr5XTXnTEoRju38ZkDPxmkx6JLywzxp0Fs1hzEgGHkFkNdTX5WqMA== X-Received: by 2002:a17:903:2307:b0:1db:b96f:4a50 with SMTP id d7-20020a170903230700b001dbb96f4a50mr5119705plh.14.1709865960807; Thu, 07 Mar 2024 18:46:00 -0800 (PST) Received: from C02CV19DML87.bytedance.net ([2001:c10:ff04:0:1000:0:1:4]) by smtp.gmail.com with ESMTPSA id q9-20020a170902b10900b001d8a93fa5b1sm15244360plr.131.2024.03.07.18.45.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Mar 2024 18:46:00 -0800 (PST) From: Rui Qi To: bp@alien8.de, mingo@redhat.com, tglx@linutronix.de, hpa@zytor.com, jpoimboe@redhat.com, peterz@infradead.org, mbenes@suse.cz, gregkh@linuxfoundation.org, stable@vger.kernel.org, alexandre.chartre@oracle.com Cc: x86@kernel.org, linux-kernel@vger.kernel.org, yuanzhu@bytedance.com, Rui Qi Subject: [PATCH v3 3/3] x86/speculation: Support intra-function call validation Date: Fri, 8 Mar 2024 10:45:18 +0800 Message-Id: <20240308024518.19294-4-qirui.001@bytedance.com> X-Mailer: git-send-email 2.39.2 (Apple Git-143) In-Reply-To: <20240308024518.19294-1-qirui.001@bytedance.com> References: <20240308024518.19294-1-qirui.001@bytedance.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" commit 8afd1c7da2b0 ("x86/speculation: Change FILL_RETURN_BUFFER to work with objtool") does not support intra-function call stack validation, which causes kernel live patching to fail. This commit adds support for this, and after testing, the kernel live patching feature is restored to normal. Fixes: 8afd1c7da2b0 ("x86/speculation: Change FILL_RETURN_BUFFER to work wi= th objtool") Cc: # v5.4.250+ Signed-off-by: Rui Qi --- arch/x86/include/asm/nospec-branch.h | 7 +++++++ arch/x86/include/asm/unwind_hints.h | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/arch/x86/include/asm/nospec-branch.h b/arch/x86/include/asm/no= spec-branch.h index c8819358a332..a88135c358c0 100644 --- a/arch/x86/include/asm/nospec-branch.h +++ b/arch/x86/include/asm/nospec-branch.h @@ -13,6 +13,8 @@ #include #include =20 +#include +#include /* * This should be used immediately before a retpoline alternative. It tells * objtool where the retpolines are so that it can make sense of the contr= ol @@ -51,14 +53,18 @@ #define __FILL_RETURN_BUFFER(reg, nr, sp) \ mov $(nr/2), reg; \ 771: \ + ANNOTATE_INTRA_FUNCTION_CALL; \ call 772f; \ 773: /* speculation trap */ \ + UNWIND_HINT_EMPTY; \ pause; \ lfence; \ jmp 773b; \ 772: \ + ANNOTATE_INTRA_FUNCTION_CALL; \ call 774f; \ 775: /* speculation trap */ \ + UNWIND_HINT_EMPTY; \ pause; \ lfence; \ jmp 775b; \ @@ -152,6 +158,7 @@ .endm =20 .macro ISSUE_UNBALANCED_RET_GUARD + ANNOTATE_INTRA_FUNCTION_CALL; call .Lunbalanced_ret_guard_\@ int3 .Lunbalanced_ret_guard_\@: diff --git a/arch/x86/include/asm/unwind_hints.h b/arch/x86/include/asm/unw= ind_hints.h index 0bcdb1279361..0fd9a22b2eca 100644 --- a/arch/x86/include/asm/unwind_hints.h +++ b/arch/x86/include/asm/unwind_hints.h @@ -101,7 +101,7 @@ ".popsection\n\t" =20 #define UNWIND_HINT_SAVE UNWIND_HINT(0, 0, UNWIND_HINT_TYPE_SAVE, 0) - +#define UNWIND_HINT_EMPTY #define UNWIND_HINT_RESTORE UNWIND_HINT(0, 0, UNWIND_HINT_TYPE_RESTORE, 0) =20 #endif /* __ASSEMBLY__ */ --=20 2.20.1