Skip to content

Commit 6076e8d

Browse files
author
CKI KWF Bot
committed
Merge: nbd: override creds to kernel when calling sock_{send,recv}msg()
MR: https://gitlab.com/redhat/centos-stream/src/kernel/centos-stream-9/-/merge_requests/7529 nbd: override creds to kernel when calling sock_{send,recv}msg() JIRA: https://issues.redhat.com/browse/RHEL-113752 Signed-off-by: Ming Lei <ming.lei@redhat.com> Approved-by: Jeff Moyer <jmoyer@redhat.com> Approved-by: John Pittman <jpittman@redhat.com> Approved-by: CKI KWF Bot <cki-ci-bot+kwf-gitlab-com@redhat.com> Merged-by: CKI GitLab Kmaint Pipeline Bot <26919896-cki-kmaint-pipeline-bot@users.noreply.gitlab.com>
2 parents 18fbb5b + 1d8e225 commit 6076e8d

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

drivers/block/nbd.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
static DEFINE_IDR(nbd_index_idr);
5353
static DEFINE_MUTEX(nbd_index_mutex);
5454
static struct workqueue_struct *nbd_del_wq;
55+
static struct cred *nbd_cred;
5556
static int nbd_total_devices = 0;
5657

5758
struct nbd_sock {
@@ -556,6 +557,7 @@ static int __sock_xmit(struct nbd_device *nbd, struct socket *sock, int send,
556557
int result;
557558
struct msghdr msg = {} ;
558559
unsigned int noreclaim_flag;
560+
const struct cred *old_cred;
559561

560562
if (unlikely(!sock)) {
561563
dev_err_ratelimited(disk_to_dev(nbd->disk),
@@ -564,6 +566,8 @@ static int __sock_xmit(struct nbd_device *nbd, struct socket *sock, int send,
564566
return -EINVAL;
565567
}
566568

569+
old_cred = override_creds(nbd_cred);
570+
567571
msg.msg_iter = *iter;
568572

569573
noreclaim_flag = memalloc_noreclaim_save();
@@ -588,6 +592,8 @@ static int __sock_xmit(struct nbd_device *nbd, struct socket *sock, int send,
588592

589593
memalloc_noreclaim_restore(noreclaim_flag);
590594

595+
revert_creds(old_cred);
596+
591597
return result;
592598
}
593599

@@ -2671,7 +2677,15 @@ static int __init nbd_init(void)
26712677
return -ENOMEM;
26722678
}
26732679

2680+
nbd_cred = prepare_kernel_cred(&init_task);
2681+
if (!nbd_cred) {
2682+
destroy_workqueue(nbd_del_wq);
2683+
unregister_blkdev(NBD_MAJOR, "nbd");
2684+
return -ENOMEM;
2685+
}
2686+
26742687
if (genl_register_family(&nbd_genl_family)) {
2688+
put_cred(nbd_cred);
26752689
destroy_workqueue(nbd_del_wq);
26762690
unregister_blkdev(NBD_MAJOR, "nbd");
26772691
return -EINVAL;
@@ -2726,6 +2740,7 @@ static void __exit nbd_cleanup(void)
27262740
/* Also wait for nbd_dev_remove_work() completes */
27272741
destroy_workqueue(nbd_del_wq);
27282742

2743+
put_cred(nbd_cred);
27292744
idr_destroy(&nbd_index_idr);
27302745
unregister_blkdev(NBD_MAJOR, "nbd");
27312746
}

0 commit comments

Comments
 (0)