Received: from smtp-fw-2101.amazon.com (smtp-fw-2101.amazon.com [72.21.196.25]) (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 E6832182AE for ; Fri, 16 Feb 2024 21:08:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=72.21.196.25 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708117688; cv=none; b=EygAEwIkw7Hi6f3asIRDK1Y5mYJVr6gtCu8qAnwN3sD0254i6MQ30USMl4oo1k2I/3xCWKDpYXNGhHY/w9uYx2t5oOo9lZdGteW2Vsn2iEGLTbiJnxqz0AKjUW3AdueOCIzLwR+BtzxUKi64qo9Fq2zjbrtwIyPQvn2uu2tX27c= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708117688; c=relaxed/simple; bh=LbrnOjDlH4KzIWW16uhxwmCY6XNn7P9yp85wyi6pg98=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=S1ihqz/ros+ExMbd3uES2E4Zhm9MPbJdu16XuQdWfd4de4GE/E+2IN4jkeRDqH3ZyfXzplt2eDBmU/WBqt6/iV/QNvIwskAT1yI5G7Vj9K9T70vF8Fn22ucQSUQq/pqlbyKtKEcLc4Eu232CeSYm8DItY5LQ8ZNib7uhHPyMPWs= 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=uNxd1M4B; arc=none smtp.client-ip=72.21.196.25 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="uNxd1M4B" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1708117687; x=1739653687; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=m7Jpjvcmw97xDssNzl3eXja6Lf+w1R0CtBQ3Io2iye0=; b=uNxd1M4Bi3X9xHqNNxUxRbbCl1jQgXYB3+GfH9q3Hju51qeaNsiCZik8 CBMC+xNW4zPeBGlJL1E3TTRuZATUfC4cmcGHj144Npgl9szOFBtqJNpj8 nzc76tXhZLHcuJe+kpaqArxJIV6kLoLn5YVZntd2YVF37JH/qjAeekvmA o=; X-IronPort-AV: E=Sophos;i="6.06,165,1705363200"; d="scan'208";a="381672856" Received: from iad12-co-svc-p1-lb1-vlan3.amazon.com (HELO smtpout.prod.us-west-2.prod.farcaster.email.amazon.dev) ([10.43.8.6]) by smtp-border-fw-2101.iad2.amazon.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Feb 2024 21:08:06 +0000 Received: from EX19MTAUWB002.ant.amazon.com [10.0.38.20:18896] by smtpin.naws.us-west-2.prod.farcaster.email.amazon.dev [10.0.63.9:2525] with esmtp (Farcaster) id 17d9ba84-01af-40d7-ba3e-bd784cd6f8bd; Fri, 16 Feb 2024 21:08:05 +0000 (UTC) X-Farcaster-Flow-ID: 17d9ba84-01af-40d7-ba3e-bd784cd6f8bd 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.1118.40; Fri, 16 Feb 2024 21:08:04 +0000 Received: from 88665a182662.ant.amazon.com.com (10.106.100.6) 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.1118.40; Fri, 16 Feb 2024 21:08:01 +0000 From: Kuniyuki Iwashima To: "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni CC: Kuniyuki Iwashima , Kuniyuki Iwashima , Subject: [PATCH v2 net-next 04/14] af_unix: Save listener for embryo socket. Date: Fri, 16 Feb 2024 13:05:46 -0800 Message-ID: <20240216210556.65913-5-kuniyu@amazon.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20240216210556.65913-1-kuniyu@amazon.com> References: <20240216210556.65913-1-kuniyu@amazon.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-ClientProxiedBy: EX19D037UWC001.ant.amazon.com (10.13.139.197) To EX19D004ANA001.ant.amazon.com (10.37.240.138) This is a prep patch for the following change, where we need to fetch the listening socket from the destination embryo socket in sendmsg(). We add a new field to struct unix_sock to save a pointer to a listening socket. We set it when connect() creates a new socket, and clear it when accept() is called. Signed-off-by: Kuniyuki Iwashima --- include/net/af_unix.h | 1 + net/unix/af_unix.c | 5 ++++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/include/net/af_unix.h b/include/net/af_unix.h index 54d62467a70b..438d2a18ba2e 100644 --- a/include/net/af_unix.h +++ b/include/net/af_unix.h @@ -79,6 +79,7 @@ struct unix_sock { struct path path; struct mutex iolock, bindlock; struct sock *peer; + struct sock *listener; struct unix_vertex vertex; struct list_head link; unsigned long inflight; diff --git a/net/unix/af_unix.c b/net/unix/af_unix.c index ea7bac18a781..1ebc3c15f972 100644 --- a/net/unix/af_unix.c +++ b/net/unix/af_unix.c @@ -992,6 +992,7 @@ static struct sock *unix_create1(struct net *net, struct socket *sock, int kern, sk->sk_max_ack_backlog = net->unx.sysctl_max_dgram_qlen; sk->sk_destruct = unix_sock_destructor; u = unix_sk(sk); + u->listener = NULL; u->inflight = 0; u->path.dentry = NULL; u->path.mnt = NULL; @@ -1611,6 +1612,7 @@ static int unix_stream_connect(struct socket *sock, struct sockaddr *uaddr, newsk->sk_type = sk->sk_type; init_peercred(newsk); newu = unix_sk(newsk); + newu->listener = other; RCU_INIT_POINTER(newsk->sk_wq, &newu->peer_wq); otheru = unix_sk(other); @@ -1706,8 +1708,8 @@ static int unix_accept(struct socket *sock, struct socket *newsock, int flags, bool kern) { struct sock *sk = sock->sk; - struct sock *tsk; struct sk_buff *skb; + struct sock *tsk; int err; err = -EOPNOTSUPP; @@ -1732,6 +1734,7 @@ static int unix_accept(struct socket *sock, struct socket *newsock, int flags, } tsk = skb->sk; + unix_sk(tsk)->listener = NULL; skb_free_datagram(sk, skb); wake_up_interruptible(&unix_sk(sk)->peer_wait); -- 2.30.2