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 1FDCF1946C4; Tue, 10 Sep 2024 10:08:10 +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=1725962890; cv=none; b=cJTcd0o7HGyUxgXq7GunTOEVmLeSCk4EZaZSuL3ate2ak4mdb6yeH/vcTWR/vQtHxBv1RLziTksOoinxkdkPM93fLJVwB48Yx2ZtsUaa+eIqkyxo23xNmOP3192UAClzHVqkOWEyFFlYWKSQ0/z/S5bCnu5kL3EvxMlyTnPb3+o= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725962890; c=relaxed/simple; bh=8ZMAa2ScooZye04cS9zcYL0U+sSZ+eaXLs48pjOlq90=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=rzTVJKDeoEM1CfzmwLqkm05J1JHzFj96QOWdratxb5YHNVV9ydBBHRLFn6dba6u+M7BrvIkDLRzUSnayFd+yxWT8yhj/Q7AYp1u0cSm2amEJ/enPxoFXqK6aaBFXxor+wTdOh0MNhQf80tj68LZRYuz3JzkKexxp90I+dddNVn8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=tPTlL8/I; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="tPTlL8/I" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6C7ECC4CEC3; Tue, 10 Sep 2024 10:08:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1725962890; bh=8ZMAa2ScooZye04cS9zcYL0U+sSZ+eaXLs48pjOlq90=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=tPTlL8/IgX2PYyytmULNLJyT93MDLh9Ud/AjNwFrr7MbwyaGidtN11nmIe0PhVT0F Jm3nD3bJT7XqHMJHufd6++f/5CuFbVO0Mj31sxM6DWmuHDSD2X53omBVQLcudq6QEd MykBYG2OCIHnWCYddN+9gya8UkFt7P64IxJ9jsj8= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Kuniyuki Iwashima , Paolo Abeni , Sasha Levin Subject: [PATCH 6.1 047/192] af_unix: Remove put_pid()/put_cred() in copy_peercred(). Date: Tue, 10 Sep 2024 11:31:11 +0200 Message-ID: <20240910092559.934676073@linuxfoundation.org> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240910092557.876094467@linuxfoundation.org> References: <20240910092557.876094467@linuxfoundation.org> User-Agent: quilt/0.67 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.1-stable review patch. If anyone has any objections, please let me know. ------------------ From: Kuniyuki Iwashima [ Upstream commit e4bd881d987121dbf1a288641491955a53d9f8f7 ] When (AF_UNIX, SOCK_STREAM) socket connect()s to a listening socket, the listener's sk_peer_pid/sk_peer_cred are copied to the client in copy_peercred(). Then, the client's sk_peer_pid and sk_peer_cred are always NULL, so we need not call put_pid() and put_cred() there. Signed-off-by: Kuniyuki Iwashima Signed-off-by: Paolo Abeni Signed-off-by: Sasha Levin --- net/unix/af_unix.c | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/net/unix/af_unix.c b/net/unix/af_unix.c index 7d59f9a6c904..5ce60087086c 100644 --- a/net/unix/af_unix.c +++ b/net/unix/af_unix.c @@ -680,9 +680,6 @@ static void init_peercred(struct sock *sk) static void copy_peercred(struct sock *sk, struct sock *peersk) { - const struct cred *old_cred; - struct pid *old_pid; - if (sk < peersk) { spin_lock(&sk->sk_peer_lock); spin_lock_nested(&peersk->sk_peer_lock, SINGLE_DEPTH_NESTING); @@ -690,16 +687,12 @@ static void copy_peercred(struct sock *sk, struct sock *peersk) spin_lock(&peersk->sk_peer_lock); spin_lock_nested(&sk->sk_peer_lock, SINGLE_DEPTH_NESTING); } - old_pid = sk->sk_peer_pid; - old_cred = sk->sk_peer_cred; + sk->sk_peer_pid = get_pid(peersk->sk_peer_pid); sk->sk_peer_cred = get_cred(peersk->sk_peer_cred); spin_unlock(&sk->sk_peer_lock); spin_unlock(&peersk->sk_peer_lock); - - put_pid(old_pid); - put_cred(old_cred); } static int unix_listen(struct socket *sock, int backlog) -- 2.43.0