Skip to content

Commit e0d4ed7

Browse files
Christoph Hellwigtrondmypd
authored andcommitted
pnfs/blocklayout: serialize GETDEVICEINFO calls
The rpc_pipefs code isn't thread safe, leading to occasional use after frees when running xfstests generic/241 (dbench). Signed-off-by: Christoph Hellwig <hch@lst.de> Link: http://lkml.kernel.org/r/1411740170-18611-2-git-send-email-hch@lst.de Cc: stable@vger.kernel.org # 3.17.x Signed-off-by: Trond Myklebust <trond.myklebust@primarydata.com>
1 parent 8c393f9 commit e0d4ed7

2 files changed

Lines changed: 10 additions & 5 deletions

File tree

‎fs/nfs/blocklayout/rpc_pipefs.c‎

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,17 +65,18 @@ bl_resolve_deviceid(struct nfs_server *server, struct pnfs_block_volume *b,
6565

6666
dprintk("%s CREATING PIPEFS MESSAGE\n", __func__);
6767

68+
mutex_lock(&nn->bl_mutex);
6869
bl_pipe_msg.bl_wq = &nn->bl_wq;
6970

7071
b->simple.len += 4; /* single volume */
7172
if (b->simple.len > PAGE_SIZE)
72-
return -EIO;
73+
goto out_unlock;
7374

7475
memset(msg, 0, sizeof(*msg));
7576
msg->len = sizeof(*bl_msg) + b->simple.len;
7677
msg->data = kzalloc(msg->len, gfp_mask);
7778
if (!msg->data)
78-
goto out;
79+
goto out_free_data;
7980

8081
bl_msg = msg->data;
8182
bl_msg->type = BL_DEVICE_MOUNT,
@@ -87,7 +88,7 @@ bl_resolve_deviceid(struct nfs_server *server, struct pnfs_block_volume *b,
8788
rc = rpc_queue_upcall(nn->bl_device_pipe, msg);
8889
if (rc < 0) {
8990
remove_wait_queue(&nn->bl_wq, &wq);
90-
goto out;
91+
goto out_free_data;
9192
}
9293

9394
set_current_state(TASK_UNINTERRUPTIBLE);
@@ -97,12 +98,14 @@ bl_resolve_deviceid(struct nfs_server *server, struct pnfs_block_volume *b,
9798
if (reply->status != BL_DEVICE_REQUEST_PROC) {
9899
printk(KERN_WARNING "%s failed to decode device: %d\n",
99100
__func__, reply->status);
100-
goto out;
101+
goto out_free_data;
101102
}
102103

103104
dev = MKDEV(reply->major, reply->minor);
104-
out:
105+
out_free_data:
105106
kfree(msg->data);
107+
out_unlock:
108+
mutex_unlock(&nn->bl_mutex);
106109
return dev;
107110
}
108111

@@ -232,6 +235,7 @@ static int nfs4blocklayout_net_init(struct net *net)
232235
struct nfs_net *nn = net_generic(net, nfs_net_id);
233236
struct dentry *dentry;
234237

238+
mutex_init(&nn->bl_mutex);
235239
init_waitqueue_head(&nn->bl_wq);
236240
nn->bl_device_pipe = rpc_mkpipe_data(&bl_upcall_ops, 0);
237241
if (IS_ERR(nn->bl_device_pipe))

‎fs/nfs/netns.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ struct nfs_net {
1919
struct rpc_pipe *bl_device_pipe;
2020
struct bl_dev_msg bl_mount_reply;
2121
wait_queue_head_t bl_wq;
22+
struct mutex bl_mutex;
2223
struct list_head nfs_client_list;
2324
struct list_head nfs_volume_list;
2425
#if IS_ENABLED(CONFIG_NFS_V4)

0 commit comments

Comments
 (0)