From mboxrd@z Thu Jan 1 00:00:00 1970 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 DFC4E3B1B3 for ; Sat, 9 May 2026 00:58:06 +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=1778288286; cv=none; b=q0dou13mY95T9y8L8aoG7B7832atKI9WUmIH5xUbZaqWWwaYJ6J3F66gca5Z6+ssYcePdiWTy9LN18iYZ9agrY8ntHNgw0lKyghZjnH2vDL+BIxnzs5okD3F/5EMiM5M4uwYkNtIsVfaRPebAUiQWeNpZGjfTmPnsw2RV8oAoiI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778288286; c=relaxed/simple; bh=REjMMagqtbdfRWljd3Hw9T9lBSFQxyuYYz2DtHl1TT8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Sn/DMCJ0BUGGPq0jmosN5Dt/6R1JTsnWHGngL9mani6SVUibwFB3gjLpwHDoByRwSJLo5Ix+atckBuvjyG635AvLuGm9AZtRcxMt6bnpv4o9EpqDlU2RoRuaMyStUojD0neMQPGCSsjKL6u0YHaEMccqGDmfksHptoneP5ewBn8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=C3SImK8+; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="C3SImK8+" Received: by smtp.kernel.org (Postfix) with ESMTPSA id BBEF9C2BCB0; Sat, 9 May 2026 00:58:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1778288286; bh=REjMMagqtbdfRWljd3Hw9T9lBSFQxyuYYz2DtHl1TT8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=C3SImK8+uyVsMfuJTLmKcvnDtNriqgLN82ibtA4e+AZBs6bk/qOKpcrl9a+3RbeFh cckjFPC4W3jObfxFUyEpu1vsuB2NLi9zp3lcc+WzmrXKjfpT7jQqJyuorhBctkOUfI a9OutkgPf399jCquRdwndGDsZY1TfrPMxb036WL3HavFmie66XZGqZicaYtk/FzhHM GjqUGMrfYi2C+051M9esGtsGMd1khZD2x45wT2opzznw8DAX6I4hXKOkgJg3+XoQ4W jiWFaQQz3ms7mXpmoNBXvOfMIzbegU0vNhRxIFpEs6MaRJjb9g7B7BytE0Anzq0t+z KQTqmJB5b6ehw== From: Sasha Levin To: stable@vger.kernel.org Cc: Cengiz Can , Qualys Security Advisory , John Johansen , Sasha Levin Subject: [PATCH 6.1.y] apparmor: use target task's context in apparmor_getprocattr() Date: Fri, 8 May 2026 20:58:02 -0400 Message-ID: <20260509005802.2568193-1-sashal@kernel.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <2026050423-wireless-sharply-fd1a@gregkh> References: <2026050423-wireless-sharply-fd1a@gregkh> Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Cengiz Can [ Upstream commit 4afc61702bdcc3b9b519749ef966cf762a6e7051 ] apparmor_getprocattr() incorrectly calls task_ctx(current) instead of task_ctx(task) when retrieving prev and exec attributes, returning the caller's labels rather than the target's. Fix by passing task to task_ctx(). The issue can be reproduced when a process with an onexec transition (e.g., configured by a container runtime) is inspected via /proc//attr/apparmor/exec. The reader's own value is returned instead of the target's. Reported-by: Qualys Security Advisory Fixes: 3b529a7600d8 ("apparmor: move task domain change info to task security") Cc: stable@vger.kernel.org Co-developed-by: Cengiz Can Signed-off-by: Cengiz Can Co-developed-by: John Johansen Signed-off-by: John Johansen Signed-off-by: Sasha Levin --- security/apparmor/lsm.c | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/security/apparmor/lsm.c b/security/apparmor/lsm.c index 97389b9c41290..b8d359b56c925 100644 --- a/security/apparmor/lsm.c +++ b/security/apparmor/lsm.c @@ -618,25 +618,23 @@ static int apparmor_getprocattr(struct task_struct *task, const char *name, char **value) { int error = -ENOENT; - /* released below */ - const struct cred *cred = get_task_cred(task); - struct aa_task_ctx *ctx = task_ctx(current); struct aa_label *label = NULL; + rcu_read_lock(); if (strcmp(name, "current") == 0) - label = aa_get_newest_label(cred_label(cred)); - else if (strcmp(name, "prev") == 0 && ctx->previous) - label = aa_get_newest_label(ctx->previous); - else if (strcmp(name, "exec") == 0 && ctx->onexec) - label = aa_get_newest_label(ctx->onexec); + label = aa_get_newest_cred_label(__task_cred(task)); + else if (strcmp(name, "prev") == 0 && task_ctx(task)->previous) + label = aa_get_newest_label(task_ctx(task)->previous); + else if (strcmp(name, "exec") == 0 && task_ctx(task)->onexec) + label = aa_get_newest_label(task_ctx(task)->onexec); else error = -EINVAL; + rcu_read_unlock(); if (label) error = aa_getprocattr(label, value); aa_put_label(label); - put_cred(cred); return error; } -- 2.53.0