Skip to content

Commit 1be5216

Browse files
Peijie Shaokeithbusch
authored andcommitted
nvme-tcp: fix selinux denied when calling sock_sendmsg
In a SELinux enabled kernel, socket_create() initializes the security label of the socket using the security label of the calling process, this typically works well. However, in a containerized environment like Kubernetes, problem arises when a privileged container(domain spc_t) connects to an NVMe target and mounts the NVMe as persistent storage for unprivileged containers(domain container_t). This is because the container_t domain cannot access resources labeled with spc_t, resulting in socket_sendmsg returning -EACCES. The solution is to use socket_create_kern() instead of socket_create(), which labels the socket context to kernel_t. Access control will then be handled by the VFS layer rather than the socket itself. Signed-off-by: Peijie Shao <[email protected]> Reviewed-by: Christoph Hellwig <[email protected]> Signed-off-by: Keith Busch <[email protected]>
1 parent 1cf0184 commit 1be5216

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

drivers/nvme/host/tcp.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1717,7 +1717,8 @@ static int nvme_tcp_alloc_queue(struct nvme_ctrl *nctrl, int qid,
17171717
queue->cmnd_capsule_len = sizeof(struct nvme_command) +
17181718
NVME_TCP_ADMIN_CCSZ;
17191719

1720-
ret = sock_create(ctrl->addr.ss_family, SOCK_STREAM,
1720+
ret = sock_create_kern(current->nsproxy->net_ns,
1721+
ctrl->addr.ss_family, SOCK_STREAM,
17211722
IPPROTO_TCP, &queue->sock);
17221723
if (ret) {
17231724
dev_err(nctrl->device,

0 commit comments

Comments
 (0)