mirror of https://github.com/torvalds/linux.git
nbd: don't copy kernel creds
No need to copy kernel credentials. Link: https://patch.msgid.link/20251103-work-creds-init_cred-v1-6-cb3ec8711a6a@kernel.org Reviewed-by: Jens Axboe <axboe@kernel.dk> Signed-off-by: Christian Brauner <brauner@kernel.org>
This commit is contained in:
parent
b9e3594e70
commit
4601b7923d
|
|
@ -52,7 +52,6 @@
|
||||||
static DEFINE_IDR(nbd_index_idr);
|
static DEFINE_IDR(nbd_index_idr);
|
||||||
static DEFINE_MUTEX(nbd_index_mutex);
|
static DEFINE_MUTEX(nbd_index_mutex);
|
||||||
static struct workqueue_struct *nbd_del_wq;
|
static struct workqueue_struct *nbd_del_wq;
|
||||||
static struct cred *nbd_cred;
|
|
||||||
static int nbd_total_devices = 0;
|
static int nbd_total_devices = 0;
|
||||||
|
|
||||||
struct nbd_sock {
|
struct nbd_sock {
|
||||||
|
|
@ -555,7 +554,6 @@ static int __sock_xmit(struct nbd_device *nbd, struct socket *sock, int send,
|
||||||
int result;
|
int result;
|
||||||
struct msghdr msg = {} ;
|
struct msghdr msg = {} ;
|
||||||
unsigned int noreclaim_flag;
|
unsigned int noreclaim_flag;
|
||||||
const struct cred *old_cred;
|
|
||||||
|
|
||||||
if (unlikely(!sock)) {
|
if (unlikely(!sock)) {
|
||||||
dev_err_ratelimited(disk_to_dev(nbd->disk),
|
dev_err_ratelimited(disk_to_dev(nbd->disk),
|
||||||
|
|
@ -564,11 +562,11 @@ static int __sock_xmit(struct nbd_device *nbd, struct socket *sock, int send,
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
old_cred = override_creds(nbd_cred);
|
|
||||||
|
|
||||||
msg.msg_iter = *iter;
|
msg.msg_iter = *iter;
|
||||||
|
|
||||||
noreclaim_flag = memalloc_noreclaim_save();
|
noreclaim_flag = memalloc_noreclaim_save();
|
||||||
|
|
||||||
|
scoped_with_kernel_creds() {
|
||||||
do {
|
do {
|
||||||
sock->sk->sk_allocation = GFP_NOIO | __GFP_MEMALLOC;
|
sock->sk->sk_allocation = GFP_NOIO | __GFP_MEMALLOC;
|
||||||
sock->sk->sk_use_task_frag = false;
|
sock->sk->sk_use_task_frag = false;
|
||||||
|
|
@ -587,11 +585,10 @@ static int __sock_xmit(struct nbd_device *nbd, struct socket *sock, int send,
|
||||||
if (sent)
|
if (sent)
|
||||||
*sent += result;
|
*sent += result;
|
||||||
} while (msg_data_left(&msg));
|
} while (msg_data_left(&msg));
|
||||||
|
}
|
||||||
|
|
||||||
memalloc_noreclaim_restore(noreclaim_flag);
|
memalloc_noreclaim_restore(noreclaim_flag);
|
||||||
|
|
||||||
revert_creds(old_cred);
|
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -2683,15 +2680,7 @@ static int __init nbd_init(void)
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
}
|
}
|
||||||
|
|
||||||
nbd_cred = prepare_kernel_cred(&init_task);
|
|
||||||
if (!nbd_cred) {
|
|
||||||
destroy_workqueue(nbd_del_wq);
|
|
||||||
unregister_blkdev(NBD_MAJOR, "nbd");
|
|
||||||
return -ENOMEM;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (genl_register_family(&nbd_genl_family)) {
|
if (genl_register_family(&nbd_genl_family)) {
|
||||||
put_cred(nbd_cred);
|
|
||||||
destroy_workqueue(nbd_del_wq);
|
destroy_workqueue(nbd_del_wq);
|
||||||
unregister_blkdev(NBD_MAJOR, "nbd");
|
unregister_blkdev(NBD_MAJOR, "nbd");
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
|
@ -2746,7 +2735,6 @@ static void __exit nbd_cleanup(void)
|
||||||
/* Also wait for nbd_dev_remove_work() completes */
|
/* Also wait for nbd_dev_remove_work() completes */
|
||||||
destroy_workqueue(nbd_del_wq);
|
destroy_workqueue(nbd_del_wq);
|
||||||
|
|
||||||
put_cred(nbd_cred);
|
|
||||||
idr_destroy(&nbd_index_idr);
|
idr_destroy(&nbd_index_idr);
|
||||||
unregister_blkdev(NBD_MAJOR, "nbd");
|
unregister_blkdev(NBD_MAJOR, "nbd");
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue