From nobody Sun Jun 2 09:31:10 2024 X-Original-To: dev-commits-src-branches@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4VsWnV3kxLz5MR5T; Sun, 02 Jun 2024 09:31:10 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4VsWnV3Cd3z4qR3; Sun, 2 Jun 2024 09:31:10 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1717320670; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=TmPk6T4NT02nw689cefW5S+jdxD9Zzb3RyHxRjOmR00=; b=hrF9ws7io/UM4bMr9PlmQIYKs75G4TdULUuuvdie8Zh0cqAlag4Ipk7+k+TAvTS/TwVrUK nPsbJtDB/SUPdNoQYNe28kDprA5+lEWbmf5iuLVJIaojmt+hDDu1JyUxUgi0EPG7teWju6 vAb3uTTfMK5qXuaPvxdWfDmmWvon1wqRBCqZs7U6rGQAwoL2TIxRM7nTIMaA0p1P5uq8XX NS2qTLfvLZQEekE5ixKZRzAGRWpLDVL62eTT4XLp0ZUG3XpDJy63jppQN569LZWC6mMX4h LaAlmeFeh0bvRriNF3RgDFlIf2gIovopEEjPHM//P1gh1x2D5sqtShV/bvyZZA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1717320670; a=rsa-sha256; cv=none; b=nbKr0wF1khpL5FRmt3XlGIpwlGcRwxvmlrmRrJu0uL8kF91CeY4O9n2Qwcp6WN2sQf9bZs pc2iKiiac6x+nhw/cq0CWwAe2C0oROq/LmpWL6QnxSw2s8xk6ZbG41ybrJAb/ukTfUhiRd afCI8DDSlOjztqYqcGMEpPJLV2XhNluD1IZuVbs1xGjMkFpFmkUsjwfiqmBbhWAJr2kTo6 3hWr7i9h1Z5XzDDEW+E4hbPgub5DXPhMjFkSMH985ItEhW3DMEy3UW5EIbIKivYcuEVA9O BjcpSB/wrT1OtHQV5kMkfO+HvdN43h1Xjjx11NB173upHden0tZt7XUEqPSepw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1717320670; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=TmPk6T4NT02nw689cefW5S+jdxD9Zzb3RyHxRjOmR00=; b=VQAqwxjX1FnuVOHXoKuqZJ9ZVbmHjP4lqa2c1Hk4CqgcV9E2LX2ttGdnZ2yZx2d6vlszz7 Sfv6zMEtY6I3A9xnBFZusqQdxBiEe76olIMK0+bwgtu4eY3j4rHLShthl/7Kq+Xf90wfQD NHH12LI5kMFFNaO2/IRfDFz82B1Kk7qtzEmFsolO4O98jW4rAlRTyqyiPR9RNyyLf/d7w/ mPQ8IaWq34K482i7Ba+rz4K/v34fRg6F/ofGfTrDHXdJKCMvBcSWHpxQUX1jV0m+hQONcA VwxhtDkPK/JdCWHMJLHMkmKWEoUCnNm9SCsibbpr08Obs8sIHMVEr6zsVa8fCg== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4VsWnV2qKmzmLT; Sun, 2 Jun 2024 09:31:10 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 4529VABr016220; Sun, 2 Jun 2024 09:31:10 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 4529VAEE016217; Sun, 2 Jun 2024 09:31:10 GMT (envelope-from git) Date: Sun, 2 Jun 2024 09:31:10 GMT Message-Id: <202406020931.4529VAEE016217@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Dimitry Andric Subject: git: c7f08a11dfbc - stable/13 - Merge commit 9f85bc834b07 from llvm-project (by Nikita Popov): List-Id: Commits to the stable branches of the FreeBSD src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-branches@freebsd.org Sender: owner-dev-commits-src-branches@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: dim X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: c7f08a11dfbc4a49f7f11a2a4a92f41bfa5ec622 Auto-Submitted: auto-generated The branch stable/13 has been updated by dim: URL: https://cgit.FreeBSD.org/src/commit/?id=c7f08a11dfbc4a49f7f11a2a4a92f41bfa5ec622 commit c7f08a11dfbc4a49f7f11a2a4a92f41bfa5ec622 Author: Dimitry Andric AuthorDate: 2024-05-30 15:35:15 +0000 Commit: Dimitry Andric CommitDate: 2024-06-02 09:30:46 +0000 Merge commit 9f85bc834b07 from llvm-project (by Nikita Popov): [PPCMergeStringPool] Only replace constant once (#92996) In #88846 I changed this code to use RAUW to perform the replacement instead of manual updates -- but kept the outer loop, which means we try to perform RAUW once per user. However, some of the users might be freed by the RAUW operation, resulting in use-after-free. The case where this happens is constant users where the replacement might result in the destruction of the original constant. Fixes https://github.com/llvm/llvm-project/issues/92991. This fixes a possible crash when building crypto/openssh/sshkey.c for PowerPC targets. Reported by: cperciva PR: 276104 MFC after: 3 days (cherry picked from commit f30188c4680a85126e793de157b851bf5ee47529) --- .../llvm/lib/Target/PowerPC/PPCMergeStringPool.cpp | 37 ++++------------------ 1 file changed, 7 insertions(+), 30 deletions(-) diff --git a/contrib/llvm-project/llvm/lib/Target/PowerPC/PPCMergeStringPool.cpp b/contrib/llvm-project/llvm/lib/Target/PowerPC/PPCMergeStringPool.cpp index ebd876d50c44..0830b02370cd 100644 --- a/contrib/llvm-project/llvm/lib/Target/PowerPC/PPCMergeStringPool.cpp +++ b/contrib/llvm-project/llvm/lib/Target/PowerPC/PPCMergeStringPool.cpp @@ -290,13 +290,6 @@ bool PPCMergeStringPool::mergeModuleStringPool(Module &M) { return true; } -static bool userHasOperand(User *TheUser, GlobalVariable *GVOperand) { - for (Value *Op : TheUser->operands()) - if (Op == GVOperand) - return true; - return false; -} - // For pooled strings we need to add the offset into the pool for each string. // This is done by adding a Get Element Pointer (GEP) before each user. This // function adds the GEP. @@ -307,29 +300,13 @@ void PPCMergeStringPool::replaceUsesWithGEP(GlobalVariable *GlobalToReplace, Indices.push_back(ConstantInt::get(Type::getInt32Ty(*Context), 0)); Indices.push_back(ConstantInt::get(Type::getInt32Ty(*Context), ElementIndex)); - // Need to save a temporary copy of each user list because we remove uses - // as we replace them. - SmallVector Users; - for (User *CurrentUser : GlobalToReplace->users()) - Users.push_back(CurrentUser); - - for (User *CurrentUser : Users) { - // The user was not found so it must have been replaced earlier. - if (!userHasOperand(CurrentUser, GlobalToReplace)) - continue; - - // We cannot replace operands in globals so we ignore those. - if (isa(CurrentUser)) - continue; - - Constant *ConstGEP = ConstantExpr::getInBoundsGetElementPtr( - PooledStructType, GPool, Indices); - LLVM_DEBUG(dbgs() << "Replacing this global:\n"); - LLVM_DEBUG(GlobalToReplace->dump()); - LLVM_DEBUG(dbgs() << "with this:\n"); - LLVM_DEBUG(ConstGEP->dump()); - GlobalToReplace->replaceAllUsesWith(ConstGEP); - } + Constant *ConstGEP = + ConstantExpr::getInBoundsGetElementPtr(PooledStructType, GPool, Indices); + LLVM_DEBUG(dbgs() << "Replacing this global:\n"); + LLVM_DEBUG(GlobalToReplace->dump()); + LLVM_DEBUG(dbgs() << "with this:\n"); + LLVM_DEBUG(ConstGEP->dump()); + GlobalToReplace->replaceAllUsesWith(ConstGEP); } } // namespace