All of lore.kernel.org
 help / color / mirror / Atom feed
From: Kuniyuki Iwashima <kuniyu@amazon.com>
To: Martin KaFai Lau <martin.lau@linux.dev>,
	Daniel Borkmann <daniel@iogearbox.net>,
	John Fastabend <john.fastabend@gmail.com>,
	"Alexei Starovoitov" <ast@kernel.org>,
	Andrii Nakryiko <andrii@kernel.org>
Cc: "Eduard Zingerman" <eddyz87@gmail.com>,
	"Song Liu" <song@kernel.org>,
	"Yonghong Song" <yonghong.song@linux.dev>,
	"KP Singh" <kpsingh@kernel.org>,
	"Stanislav Fomichev" <sdf@fomichev.me>,
	"Hao Luo" <haoluo@google.com>, "Jiri Olsa" <jolsa@kernel.org>,
	"Mickaël Salaün" <mic@digikod.net>,
	"Günther Noack" <gnoack@google.com>,
	"Paul Moore" <paul@paul-moore.com>,
	"James Morris" <jmorris@namei.org>,
	"Serge E. Hallyn" <serge@hallyn.com>,
	"Stephen Smalley" <stephen.smalley.work@gmail.com>,
	"Ondrej Mosnacek" <omosnace@redhat.com>,
	"Casey Schaufler" <casey@schaufler-ca.com>,
	"Christian Brauner" <brauner@kernel.org>,
	"Kuniyuki Iwashima" <kuniyu@amazon.com>,
	"Kuniyuki Iwashima" <kuni1840@gmail.com>,
	bpf@vger.kernel.org, netdev@vger.kernel.org,
	linux-security-module@vger.kernel.org, selinux@vger.kernel.org
Subject: [PATCH v1 bpf-next 3/5] af_unix: Remove redundant scm->fp check in __scm_destroy().
Date: Mon, 5 May 2025 14:56:48 -0700	[thread overview]
Message-ID: <20250505215802.48449-4-kuniyu@amazon.com> (raw)
In-Reply-To: <20250505215802.48449-1-kuniyu@amazon.com>

__scm_destroy() is called from __scm_recv_common() or
scm_destroy(), and both of which check if scm->fp is NULL.

Let's remove the redundant scm->fp check in __scm_destroy().

While at it, we remove EXPORT_SYMBOL() for it and rename it
to scm_fp_destroy() to make the following patch clearer.

Signed-off-by: Kuniyuki Iwashima <kuniyu@amazon.com>
---
 include/net/scm.h |  5 +++--
 net/compat.c      |  2 +-
 net/core/scm.c    | 19 +++++++++----------
 3 files changed, 13 insertions(+), 13 deletions(-)

diff --git a/include/net/scm.h b/include/net/scm.h
index 22bb49589fde..058688a16a63 100644
--- a/include/net/scm.h
+++ b/include/net/scm.h
@@ -53,7 +53,7 @@ struct scm_cookie {
 void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm);
 void scm_detach_fds_compat(struct msghdr *msg, struct scm_cookie *scm);
 int __scm_send(struct socket *sock, struct msghdr *msg, struct scm_cookie *scm);
-void __scm_destroy(struct scm_cookie *scm);
+void scm_fp_destroy(struct scm_cookie *scm);
 struct scm_fp_list *scm_fp_dup(struct scm_fp_list *fpl);
 
 #ifdef CONFIG_SECURITY_NETWORK
@@ -84,8 +84,9 @@ static __inline__ void scm_destroy_cred(struct scm_cookie *scm)
 static __inline__ void scm_destroy(struct scm_cookie *scm)
 {
 	scm_destroy_cred(scm);
+
 	if (scm->fp)
-		__scm_destroy(scm);
+		scm_fp_destroy(scm);
 }
 
 static __inline__ int scm_send(struct socket *sock, struct msghdr *msg,
diff --git a/net/compat.c b/net/compat.c
index 485db8ee9b28..6689a4f37bcf 100644
--- a/net/compat.c
+++ b/net/compat.c
@@ -326,7 +326,7 @@ void scm_detach_fds_compat(struct msghdr *msg, struct scm_cookie *scm)
 	 * All of the files that fit in the message have had their usage counts
 	 * incremented, so we just free the list.
 	 */
-	__scm_destroy(scm);
+	scm_fp_destroy(scm);
 }
 
 /* Argument list sizes for compat_sys_socketcall */
diff --git a/net/core/scm.c b/net/core/scm.c
index 733c0cbd393d..bef8d008f910 100644
--- a/net/core/scm.c
+++ b/net/core/scm.c
@@ -130,20 +130,19 @@ static int scm_fp_copy(struct cmsghdr *cmsg, struct scm_fp_list **fplp)
 	return num;
 }
 
-void __scm_destroy(struct scm_cookie *scm)
+void scm_fp_destroy(struct scm_cookie *scm)
 {
 	struct scm_fp_list *fpl = scm->fp;
 	int i;
 
-	if (fpl) {
-		scm->fp = NULL;
-		for (i=fpl->count-1; i>=0; i--)
-			fput(fpl->fp[i]);
-		free_uid(fpl->user);
-		kfree(fpl);
-	}
+	scm->fp = NULL;
+
+	for (i = fpl->count - 1; i >= 0; i--)
+		fput(fpl->fp[i]);
+
+	free_uid(fpl->user);
+	kfree(fpl);
 }
-EXPORT_SYMBOL(__scm_destroy);
 
 int __scm_send(struct socket *sock, struct msghdr *msg, struct scm_cookie *p)
 {
@@ -375,7 +374,7 @@ void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
 	 * All of the files that fit in the message have had their usage counts
 	 * incremented, so we just free the list.
 	 */
-	__scm_destroy(scm);
+	scm_fp_destroy(scm);
 }
 EXPORT_SYMBOL(scm_detach_fds);
 
-- 
2.49.0


  parent reply	other threads:[~2025-05-05 21:59 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-05-05 21:56 [PATCH v1 bpf-next 0/5] af_unix: Allow BPF LSM to scrub SCM_RIGHTS at sendmsg() Kuniyuki Iwashima
2025-05-05 21:56 ` [PATCH v1 bpf-next 1/5] af_unix: Call security_unix_may_send() in sendmsg() for all socket types Kuniyuki Iwashima
2025-05-05 21:56 ` [PATCH v1 bpf-next 2/5] af_unix: Pass skb to security_unix_may_send() Kuniyuki Iwashima
2025-05-05 21:56 ` Kuniyuki Iwashima [this message]
2025-05-09 14:13   ` [PATCH v1 bpf-next 3/5] af_unix: Remove redundant scm->fp check in __scm_destroy() kernel test robot
2025-05-05 21:56 ` [PATCH v1 bpf-next 4/5] bpf: Add kfunc to scrub SCM_RIGHTS at security_unix_may_send() Kuniyuki Iwashima
2025-05-06  0:13   ` Alexei Starovoitov
2025-05-06  8:25     ` Mickaël Salaün
2025-05-09 15:06   ` kernel test robot
2025-05-05 21:56 ` [PATCH v1 bpf-next 5/5] selftest: bpf: Add test for bpf_unix_scrub_fds() Kuniyuki Iwashima
2025-05-05 22:49 ` [PATCH v1 bpf-next 0/5] af_unix: Allow BPF LSM to scrub SCM_RIGHTS at sendmsg() Kumar Kartikeya Dwivedi
2025-05-06  0:21   ` Kuniyuki Iwashima
2025-05-06 16:25     ` Kumar Kartikeya Dwivedi
2025-05-06 18:16       ` Kuniyuki Iwashima
2025-05-06  9:15   ` Christian Brauner
2025-05-06 16:08     ` Kumar Kartikeya Dwivedi
2025-05-06 18:14       ` Kuniyuki Iwashima
2025-05-05 23:21 ` Paul Moore
2025-05-06  0:35   ` Kuniyuki Iwashima
2025-05-06 14:57     ` Paul Moore
2025-05-06 12:17 ` Lennart Poettering
2025-05-06 18:19   ` Kuniyuki Iwashima

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250505215802.48449-4-kuniyu@amazon.com \
    --to=kuniyu@amazon.com \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=brauner@kernel.org \
    --cc=casey@schaufler-ca.com \
    --cc=daniel@iogearbox.net \
    --cc=eddyz87@gmail.com \
    --cc=gnoack@google.com \
    --cc=haoluo@google.com \
    --cc=jmorris@namei.org \
    --cc=john.fastabend@gmail.com \
    --cc=jolsa@kernel.org \
    --cc=kpsingh@kernel.org \
    --cc=kuni1840@gmail.com \
    --cc=linux-security-module@vger.kernel.org \
    --cc=martin.lau@linux.dev \
    --cc=mic@digikod.net \
    --cc=netdev@vger.kernel.org \
    --cc=omosnace@redhat.com \
    --cc=paul@paul-moore.com \
    --cc=sdf@fomichev.me \
    --cc=selinux@vger.kernel.org \
    --cc=serge@hallyn.com \
    --cc=song@kernel.org \
    --cc=stephen.smalley.work@gmail.com \
    --cc=yonghong.song@linux.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.