From patchwork Tue Jun 11 22:29:04 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kuniyuki Iwashima X-Patchwork-Id: 13694258 X-Patchwork-Delegate: kuba@kernel.org Received: from smtp-fw-80006.amazon.com (smtp-fw-80006.amazon.com [99.78.197.217]) (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 AA62F15278E for ; Tue, 11 Jun 2024 22:33:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=99.78.197.217 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718145206; cv=none; b=JDTq9XIfsfbNOJ4bw0kpbvMonTbio8/uMdqafyBfG1b9Gb13zyYoX5UdBMCp/MwfJy1IxDER7g5062PnB6DpRJl15W1EPxRHHe4RknI9nB28HiBjkeoBkUITQudkVV374dxRT3sMW/rWZZEz6ob1+YKzs0XEoz46tbKDYKNZlYE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718145206; c=relaxed/simple; bh=EMk+iik9v3qieNjTuTqUnT0QPtkv0BXbdgKiWy5Rtrk=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=IoED5M5CeXLHImtS5U2gmp7wS/8mVT4WyiVzLV/8QwmsBQPsFgRGIK8yAoAjUYI1sQVyvfU99o8Zw3JnCgGLVh1IZlBtr40Ovtseuo71BW5ORRnibH3mhOLb1j+40J+wGIMoDJ/FneL8uNdnon8wg/9fqm5mQXezEgrA3Y6dcfI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amazon.com; spf=pass smtp.mailfrom=amazon.co.jp; dkim=pass (1024-bit key) header.d=amazon.com header.i=@amazon.com header.b=MgOKaUK3; arc=none smtp.client-ip=99.78.197.217 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amazon.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=amazon.co.jp Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amazon.com header.i=@amazon.com header.b="MgOKaUK3" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1718145204; x=1749681204; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=n6umSye6/wWyRGg5S1NDMy2+8kptXod8os+SqARNZzc=; b=MgOKaUK3C4dLAfN8nGHbVFTRyT1XDyJ3QZI4V3DYe2cqi71JIx5gVOy4 61Bp5K334pt9hjTFZtsH4wNOjrKuO6UsqpLoiTX0OmUz9D16SfDZ/zhL1 zleFYUttcE0NuiWn2E2X4zZmXn9FZ6RUM6iTy/AGpbCJaOMkBUfg7CBAE 4=; X-IronPort-AV: E=Sophos;i="6.08,231,1712620800"; d="scan'208";a="301554114" Received: from pdx4-co-svc-p1-lb2-vlan3.amazon.com (HELO smtpout.prod.us-west-2.prod.farcaster.email.amazon.dev) ([10.25.36.214]) by smtp-border-fw-80006.pdx80.corp.amazon.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Jun 2024 22:33:22 +0000 Received: from EX19MTAUWA002.ant.amazon.com [10.0.38.20:51795] by smtpin.naws.us-west-2.prod.farcaster.email.amazon.dev [10.0.35.14:2525] with esmtp (Farcaster) id 6afcacd3-5938-48bb-9766-952019d44091; Tue, 11 Jun 2024 22:33:21 +0000 (UTC) X-Farcaster-Flow-ID: 6afcacd3-5938-48bb-9766-952019d44091 Received: from EX19D004ANA001.ant.amazon.com (10.37.240.138) by EX19MTAUWA002.ant.amazon.com (10.250.64.202) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1258.34; Tue, 11 Jun 2024 22:33:21 +0000 Received: from 88665a182662.ant.amazon.com.com (10.187.171.17) by EX19D004ANA001.ant.amazon.com (10.37.240.138) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA) id 15.2.1258.34; Tue, 11 Jun 2024 22:33:18 +0000 From: Kuniyuki Iwashima To: "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni CC: Kent Overstreet , Kuniyuki Iwashima , Kuniyuki Iwashima , Subject: [PATCH v2 net-next 10/11] af_unix: Remove put_pid()/put_cred() in copy_peercred(). Date: Tue, 11 Jun 2024 15:29:04 -0700 Message-ID: <20240611222905.34695-11-kuniyu@amazon.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20240611222905.34695-1-kuniyu@amazon.com> References: <20240611222905.34695-1-kuniyu@amazon.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: EX19D045UWA001.ant.amazon.com (10.13.139.83) To EX19D004ANA001.ant.amazon.com (10.37.240.138) X-Patchwork-Delegate: kuba@kernel.org 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 --- 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 6a73c5ad67ac..64bfd25a6b31 100644 --- a/net/unix/af_unix.c +++ b/net/unix/af_unix.c @@ -757,9 +757,6 @@ static void update_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); @@ -767,16 +764,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)