From patchwork Mon Jun 10 22:35:00 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kuniyuki Iwashima X-Patchwork-Id: 13692501 X-Patchwork-Delegate: kuba@kernel.org Received: from smtp-fw-9102.amazon.com (smtp-fw-9102.amazon.com [207.171.184.29]) (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 B00B15466B for ; Mon, 10 Jun 2024 22:39:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=207.171.184.29 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718059167; cv=none; b=P6RLXUcwlbsla7HSMyBoUU4p0PI9IWoos8XBOK921Qz5F6+5Zy34wDp2LD2O1TzZ1Agyz28o1U0I4ceIvB6rHOvw+2fwPoMP04YWir3IcX191FnHTvaURl+2v0Op5BFf+AiysbuwINU6BCJjRE5JnJ6DWgp/8fweXsvKY+LBc7I= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718059167; c=relaxed/simple; bh=AMBTFgsjMF1RWwfGVtNo+ileC2fg+NI6BvfcYw1YrjA=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=mfny4unNSSybBd0phWLsMgJ37juWQFo7maZDcw9EG/5yoGYTqX9hv1tkMYfh/raj88dZuNqiMoqMnZK13H+UeOe9S/L7/BoEgcL6yg41kgl9ckq7BvkAYYd3LqD1zCTbBGyosmVIYgf0iryV5ZATl91fw0XyexvJliRdAPltntE= 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=Y85sjc2+; arc=none smtp.client-ip=207.171.184.29 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="Y85sjc2+" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1718059165; x=1749595165; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=4C9apDZB+04wuRWhwgi5c1fIty6gaJxNUmoXC7khm+Q=; b=Y85sjc2+p6MRfQA54FQ8jwch33GfeFsmY1MBbXAz6wZN+zu5xZSFHVrf P3Gs/8JOnPbwLYCNpNSgt1kq9f+Vf9/sKNu8EiEiIMeatZYqUZHY3y8+d kOLohgClEXzv5opR4svWIuAwd2gi+ehS0Qq0nAoSMbu/8AgL4Ubaf8GzS w=; X-IronPort-AV: E=Sophos;i="6.08,228,1712620800"; d="scan'208";a="425325406" 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-9102.sea19.amazon.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Jun 2024 22:39:19 +0000 Received: from EX19MTAUWB002.ant.amazon.com [10.0.38.20:53767] by smtpin.naws.us-west-2.prod.farcaster.email.amazon.dev [10.0.50.129:2525] with esmtp (Farcaster) id df4d4de2-2b06-47c3-a326-7a10ccc94f8b; Mon, 10 Jun 2024 22:39:19 +0000 (UTC) X-Farcaster-Flow-ID: df4d4de2-2b06-47c3-a326-7a10ccc94f8b Received: from EX19D004ANA001.ant.amazon.com (10.37.240.138) by EX19MTAUWB002.ant.amazon.com (10.250.64.231) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1258.34; Mon, 10 Jun 2024 22:39:19 +0000 Received: from 88665a182662.ant.amazon.com.com (10.187.171.27) by EX19D004ANA001.ant.amazon.com (10.37.240.138) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1258.34; Mon, 10 Jun 2024 22:39:16 +0000 From: Kuniyuki Iwashima To: "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni CC: Kent Overstreet , Kuniyuki Iwashima , Kuniyuki Iwashima , Subject: [PATCH v1 net-next 10/11] af_unix: Remove put_pid()/put_cred() in copy_peercred(). Date: Mon, 10 Jun 2024 15:35:00 -0700 Message-ID: <20240610223501.73191-11-kuniyu@amazon.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20240610223501.73191-1-kuniyu@amazon.com> References: <20240610223501.73191-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: EX19D032UWA004.ant.amazon.com (10.13.139.56) 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 9070e3d67736..7d9c4c9b6f85 100644 --- a/net/unix/af_unix.c +++ b/net/unix/af_unix.c @@ -755,9 +755,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); @@ -765,16 +762,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)