From patchwork Tue Feb 27 07:35:27 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josh Poimboeuf X-Patchwork-Id: 207077 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:a81b:b0:108:e6aa:91d0 with SMTP id bq27csp2545529dyb; Mon, 26 Feb 2024 23:43:09 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVx9GRSrQlgRiKbCJfnqZmOY/8rTWOw5fNKTRY/IJwTCIm2Wi5z+alk6buhyFnqsZebMVzsDPAfCe/LNOkFP/ZfG8eQ3w== X-Google-Smtp-Source: AGHT+IFXACZKSsNtHPCqdqrXuKNJNfEALIWU17BPA1APo00Z5Nejy5Oy8pCqy5e1MMidLmj5qxWE X-Received: by 2002:a17:902:f709:b0:1dc:a8aa:3c86 with SMTP id h9-20020a170902f70900b001dca8aa3c86mr4578559plo.5.1709019788912; Mon, 26 Feb 2024 23:43:08 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709019788; cv=pass; d=google.com; s=arc-20160816; b=1ANgFNPjwMChM3vuU2rD61q45xDhvBo8DwVx9Q6N4BBq4vZmTlcfqixg2hlnxeU4KK 6yZiyyB7z+KKF6WxF3a5cyry08eXRv7/VkBJcgwEfGjjoKogGb9CtrPKVxVWRWnG8xg8 +vu8A8leSK4SnE8ZJ9ZpAEo47VHSl+xIDagR/MuuccJxg9FyOjtmfWbTj04WhAbHoTa8 KTbbxY5mNmwBQndzUTiISWHR2RqYaOtHXpfeCbdlMXEgjcZU5OfFoxgjZGMPenIErTpb pzd77MBnJzgQ52Zi4Tm0qO3QrrI8BEU2N6L/pTlUb0/8drvdofvcqbtvtQbQdLa6vRjI JQkA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date:dkim-signature; bh=ILkLcKMHJuVr7zQ39P32oXFEHNpDDeUqbtY3qTlDtdY=; fh=f3Jgpo/QK/zubOYJ3FEMfyCU8d2aHinryc3/+76lGiE=; b=u909hLklQexUJ4ils/3FxW0w0qymcZTzrpexkiTzd7k+BRRrRvQes1tnFO7pWEacTa SEjTeIXvazabFKQRPlgfBrWDDBEt+WDpzizarvPJ/8ZuL012ontmo/kYyirgJDuwRlOt nGuJtpDa+ZE7z0YBaNBdJXONS8Xlg9mFrBknv0k3ocnHZAlGKTmeOGNsOxOzN/ZzgFEC /EMPe+r4lWDNwWIr/eIoDNXuwZGVr/M9HOJMwEBY+H8ZuyfkK+l/6gLQmuVoRjRF8rEf X7ExObTQbhrRLbMMFGTPMhkrpftOVH/k70vyAel9VTy0qtcOiOWMy3UzUs6/qj5fLAGE mGtQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=KQPJ6f7u; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-82807-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-82807-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id ju17-20020a170903429100b001dc6770e4d0si944395plb.132.2024.02.26.23.43.08 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Feb 2024 23:43:08 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-82807-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=KQPJ6f7u; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-82807-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-82807-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 24956B2551E for ; Tue, 27 Feb 2024 07:35:58 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 0AF5B54BC8; Tue, 27 Feb 2024 07:35:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="KQPJ6f7u" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 43B3A54BEF; Tue, 27 Feb 2024 07:35:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709019331; cv=none; b=rWg801GNkgUTEtB6yFlxUcnQZVTVkCBmA/tLSotwmZSuJbNkjB6JNPxSrmuPcU/bAG48R9uUJaANBzLiAeRzc8ipEW/Z64qGHk3SURqWxPI22bYyWc9rcHelslS/3zx6O1dd8fLi45vrkfi2FmONZ1MUqwySnTNTxsNGa5tFT+8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709019331; c=relaxed/simple; bh=y3D8WUkWKPmkFY3KmSBBbE7wj43kaGpM0J+XoS+kZLk=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=mizGi0FLiOQ1pOWdNQGTy68JkHbcw9V8Il+GdQ54GnWciJcI6hD3eXICNYHn0PexdhLCNJJ5W4k0WYuhziTqI9jQUjuyOf2NhsWZL8BaqjeI8RW8VIJkdgXNc1YkWEcf11zh50j6809DzV1P/wUr/u9XjB/OZGSsayT2IaDHv4Y= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=KQPJ6f7u; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5481DC433F1; Tue, 27 Feb 2024 07:35:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1709019329; bh=y3D8WUkWKPmkFY3KmSBBbE7wj43kaGpM0J+XoS+kZLk=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=KQPJ6f7ug8Rcs+DxLj4aM6bqai7HwJ1Jig7eLPf79CJ41+TQuTnxTQb2+yU/JzFNn 7/zJlyV0Nkrx1LumAZ+f5pmChx4ctfSC6iA5GxQ9U8vScWtkB3Afc1fGTzaoYV54W+ 82xOhGUNBqdEl6Hp9WZ6LEOf8JD0L9afQDSO9mRd1/gT2Sspp7dJ4dDZl/6Q05444U R2TOFWTb3J3FqfYpvN6G6GDCxuelsF2Nxep3FJszvjxmOwBqYdG4FhK7b90GB0Tn7E LKBR/RP+pd4rFNaBxDt1zYmcSzN++OiFu8o/hqJmlCMddbQSYm9EAjmaSUiDOdaHBi qOrNJX7crk8pw== Date: Mon, 26 Feb 2024 23:35:27 -0800 From: Josh Poimboeuf To: Kees Cook Cc: Peter Zijlstra , oe-kbuild-all@lists.linux.dev, kernel test robot , Alexander Lobakin , linux-kernel@vger.kernel.org Subject: [PATCH] objtool: Fix UNWIND_HINT_{SAVE,RESTORE} across basic blocks Message-ID: <20240227073527.avcm5naavbv3cj5s@treble> References: <202402240702.zJFNmahW-lkp@intel.com> <202402231632.D90831AE51@keescook> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <202402231632.D90831AE51@keescook> X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1792037134167052294 X-GMAIL-MSGID: 1792037134167052294 On Fri, Feb 23, 2024 at 04:45:22PM -0800, Kees Cook wrote: > Josh, Peter, can you give a clue about what's happened here? For > added context, the referenced commit is changing a noreturn function > prototype[1], which I know gets some special objtool handling, but it's > converting a pointer arg to a u8... I can't imagine what has gone weird > here. :P I think this convinced GCC to reshuffle some basic blocks, which uncovered an objtool bug. Or, objtool just wasn't smart enough, as the warning says ;-) This should fix it, absent any more warnings. Kees, feel free to take it in your branch if that helps. ---8<--- From: Josh Poimboeuf Subject: [PATCH] objtool: Fix UNWIND_HINT_{SAVE,RESTORE} across basic blocks If SAVE and RESTORE unwind hints are in different basic blocks, and objtool sees the RESTORE before the SAVE, it errors out with: vmlinux.o: warning: objtool: vmw_port_hb_in+0x242: objtool isn't smart enough to handle this CFI save/restore combo In such a case, defer following the RESTORE block until the straight-line path gets followed later. Fixes: 8faea26e6111 ("objtool: Re-add UNWIND_HINT_{SAVE_RESTORE}") Reported-by: kernel test robot Closes: https://lore.kernel.org/oe-kbuild-all/202402240702.zJFNmahW-lkp@intel.com/ Signed-off-by: Josh Poimboeuf --- tools/objtool/check.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/tools/objtool/check.c b/tools/objtool/check.c index 548ec3cd7c00..c4c2f75eadfd 100644 --- a/tools/objtool/check.c +++ b/tools/objtool/check.c @@ -3620,6 +3620,18 @@ static int validate_branch(struct objtool_file *file, struct symbol *func, } if (!save_insn->visited) { + /* + * If the restore hint insn is at the + * beginning of a basic block and was + * branched to from elsewhere, and the + * save insn hasn't been visited yet, + * defer following this branch for now. + * It will be seen later via the + * straight-line path. + */ + if (!prev_insn) + return 0; + WARN_INSN(insn, "objtool isn't smart enough to handle this CFI save/restore combo"); return 1; }