On Sat, Nov 21, 2026 at 11:21:13AM +0000, Suyuan Wang wrote:
> From: Suyuan Wang <stev…@hust.edu.cn> > > NFC_CMD_SE_IO sends an APDU to a secure element and needs CAP_NET_ADMIN > (GENL_ADMIN_PERM). The response from the secure element is not sent > back to the requester, though: se_io_cb() multicasts it with > NFC_ATTR_SE_APDU on the "events" group, and generic netlink lets any > user join that group. So an unprivileged user can read every response > APDU that a privileged process exchanges with the secure element. > > The response has to stay on the multicast group, because that is where > userspace reads it: neard's seeld sends NFC_CMD_SE_IO on one socket and > handles the response on the socket it has subscribed to "events". > Requiring CAP_NET_ADMIN for the whole group would also hide the device > and target events from unprivileged listeners. > > So keep the multicast, but filter the receivers: deliver the SE_IO > response only to sockets that were opened with CAP_NET_ADMIN in the > initial user namespace, the capability that NFC_CMD_SE_IO itself needs. > The check uses the credentials of the socket's opener, as > do_one_broadcast() does, because se_io_cb() runs in the driver's > context; a socket opened by a privileged process still gets the > response after the process drops the capability or passes the socket > on. Kernel sockets have no file and are skipped. Other events on the > group are not affected. > > Found with a static analysis tool and checked by hand. > > Fixes: 5ce3f32b5264 ("NFC: netlink: SE API implementation") > Cc: stab…@vger.kernel.org > Co-developed-by: Kaixuan Li <kaix…@ntu.edu.sg> > Signed-off-by: Kaixuan Li <kaix…@ntu.edu.sg> > Signed-off-by: Suyuan Wang <stev…@hust.edu.cn> > --- > Tested in QEMU (x86_64, KASAN) with a test-only NFC driver whose se_io > answers from a work item. Four listeners subscribe to "events": root; > a socket opened by root that then drops CAP_NET_ADMIN; and two sockets > opened without the capability (root without CAP_NET_ADMIN, nobody). > Root then does DEV_UP (which adds the secure element), ENABLE_SE and > SE_IO. > > Before: all four get SE_ADDED and the SE_IO response with the APDU. > After: root and the socket opened by root get both; the two sockets > opened without the capability get SE_ADDED only. > > Not tested on hardware (st21nfca and st-nci implement se_io).
Reviewed-by: Simon Horman <hor…@kernel.org>