From: Suyuan Wang via B4 Relay <devnull+shyckless.gmail.com@kernel.org>
To: netdev@vger.kernel.org, david@ixit.cz
Cc: edumazet@kernel.org, kuba@kernel.org, horms@kernel.org,
oe-linux-nfc@lists.linux.dev, linux-kernel@vger.kernel.org,
pabeni@redhat.com, davem@davemloft.net
Subject: [PATCH net 1/2] nfc: llcp: Clone LSM attributes to newly created child sockets
Date: Thu, 12 Nov 2026 10:04:48 +0000 [thread overview]
Message-ID: <20261112-nfc-v1-1-ab0ef166f382@gmail.com> (raw)
In-Reply-To: <20261112-nfc-v1-0-ab0ef166f382@gmail.com>
From: Suyuan Wang <stevewong@hust.edu.cn>
nfc_llcp_recv_connect() creates the child socket for an incoming
CONNECT and queues it for accept(), but never calls security_sk_clone():
new_sk = nfc_llcp_sock_alloc(NULL, parent->sk_type, GFP_ATOMIC, 0);
...
new_sock = nfc_llcp_sock(new_sk);
So the accepted socket doesn't inherit the LSM state of the listening
socket. With SELinux, its sock keeps the unlabeled SID. The
sock_has_perm() checks on it (sendmsg, recvmsg and so on) still run,
but against that SID instead of the server's. Depending on the policy,
this can deny a confined server on its own accepted sockets, or allow
something the server's own label wouldn't.
Call security_sk_clone() right after the child is allocated, before it
is set up and queued for accept(). Bluetooth, iucv and vsock fixed the
same problem the same way, in commit 6230c9b4f895 ("bluetooth: Properly
clone LSM attributes to newly created child connections"),
commit 02f06918156b ("iucv: properly clone LSM attributes to newly
created child sockets") and commit 1f935e8e72ec ("selinux: vsock: Set
SID for socket returned by accept()").
Found with a static analysis tool and checked by hand.
Fixes: d646960f7986 ("NFC: Initial LLCP support")
Cc: stable@vger.kernel.org
Co-developed-by: Kaixuan Li <kaixuan.li@ntu.edu.sg>
Signed-off-by: Kaixuan Li <kaixuan.li@ntu.edu.sg>
Signed-off-by: Suyuan Wang <stevewong@hust.edu.cn>
---
Compile tested only, I haven't tried it with an SELinux policy and a
real LLCP peer.
---
net/nfc/llcp_core.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/net/nfc/llcp_core.c b/net/nfc/llcp_core.c
index 74bf817007cf..0f54548a47cc 100644
--- a/net/nfc/llcp_core.c
+++ b/net/nfc/llcp_core.c
@@ -10,6 +10,7 @@
#include <linux/kernel.h>
#include <linux/list.h>
#include <linux/nfc.h>
+#include <linux/security.h>
#include "nfc.h"
#include "llcp.h"
@@ -1006,6 +1007,8 @@ static void nfc_llcp_recv_connect(struct nfc_llcp_local *local,
goto fail;
}
+ security_sk_clone(parent, new_sk);
+
new_sock = nfc_llcp_sock(new_sk);
new_sock->local = nfc_llcp_local_get(local);
--
2.34.1
WARNING: multiple messages have this Message-ID (diff)
From: Suyuan Wang <shyckless@gmail.com>
To: netdev@vger.kernel.org, david@ixit.cz
Cc: edumazet@kernel.org, kuba@kernel.org, horms@kernel.org,
oe-linux-nfc@lists.linux.dev, linux-kernel@vger.kernel.org,
pabeni@redhat.com, davem@davemloft.net
Subject: [PATCH net 1/2] nfc: llcp: Clone LSM attributes to newly created child sockets
Date: Thu, 12 Nov 2026 10:04:48 +0000 [thread overview]
Message-ID: <20261112-nfc-v1-1-ab0ef166f382@gmail.com> (raw)
In-Reply-To: <20261112-nfc-v1-0-ab0ef166f382@gmail.com>
From: Suyuan Wang <stevewong@hust.edu.cn>
nfc_llcp_recv_connect() creates the child socket for an incoming
CONNECT and queues it for accept(), but never calls security_sk_clone():
new_sk = nfc_llcp_sock_alloc(NULL, parent->sk_type, GFP_ATOMIC, 0);
...
new_sock = nfc_llcp_sock(new_sk);
So the accepted socket doesn't inherit the LSM state of the listening
socket. With SELinux, its sock keeps the unlabeled SID. The
sock_has_perm() checks on it (sendmsg, recvmsg and so on) still run,
but against that SID instead of the server's. Depending on the policy,
this can deny a confined server on its own accepted sockets, or allow
something the server's own label wouldn't.
Call security_sk_clone() right after the child is allocated, before it
is set up and queued for accept(). Bluetooth, iucv and vsock fixed the
same problem the same way, in commit 6230c9b4f895 ("bluetooth: Properly
clone LSM attributes to newly created child connections"),
commit 02f06918156b ("iucv: properly clone LSM attributes to newly
created child sockets") and commit 1f935e8e72ec ("selinux: vsock: Set
SID for socket returned by accept()").
Found with a static analysis tool and checked by hand.
Fixes: d646960f7986 ("NFC: Initial LLCP support")
Cc: stable@vger.kernel.org
Co-developed-by: Kaixuan Li <kaixuan.li@ntu.edu.sg>
Signed-off-by: Kaixuan Li <kaixuan.li@ntu.edu.sg>
Signed-off-by: Suyuan Wang <stevewong@hust.edu.cn>
---
Compile tested only, I haven't tried it with an SELinux policy and a
real LLCP peer.
---
net/nfc/llcp_core.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/net/nfc/llcp_core.c b/net/nfc/llcp_core.c
index 74bf817007cf..0f54548a47cc 100644
--- a/net/nfc/llcp_core.c
+++ b/net/nfc/llcp_core.c
@@ -10,6 +10,7 @@
#include <linux/kernel.h>
#include <linux/list.h>
#include <linux/nfc.h>
+#include <linux/security.h>
#include "nfc.h"
#include "llcp.h"
@@ -1006,6 +1007,8 @@ static void nfc_llcp_recv_connect(struct nfc_llcp_local *local,
goto fail;
}
+ security_sk_clone(parent, new_sk);
+
new_sock = nfc_llcp_sock(new_sk);
new_sock->local = nfc_llcp_local_get(local);
--
2.34.1
next prev parent reply other threads:[~2026-11-12 10:04 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-12 10:04 [PATCH net 0/2] nfc: llcp: clone LSM attributes; st21nfca: fix skb leak Suyuan Wang via B4 Relay
2026-11-12 10:04 ` Suyuan Wang
2026-11-12 10:04 ` Suyuan Wang via B4 Relay [this message]
2026-11-12 10:04 ` [PATCH net 1/2] nfc: llcp: Clone LSM attributes to newly created child sockets Suyuan Wang
2026-11-18 18:16 ` Simon Horman
2026-11-12 10:04 ` [PATCH net 2/2] nfc: st21nfca: Free the ATR_REQ skb after sending it Suyuan Wang via B4 Relay
2026-11-12 10:04 ` Suyuan Wang
2026-11-18 18:16 ` Simon Horman
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=20261112-nfc-v1-1-ab0ef166f382@gmail.com \
--to=devnull+shyckless.gmail.com@kernel.org \
--cc=davem@davemloft.net \
--cc=david@ixit.cz \
--cc=edumazet@kernel.org \
--cc=horms@kernel.org \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=oe-linux-nfc@lists.linux.dev \
--cc=pabeni@redhat.com \
--cc=shyckless@gmail.com \
/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.