Skip to content

Commit 717e6f2

Browse files
ukernelidryomov
authored andcommitted
ceph: avoid panic in create_session_open_msg() if utsname() returns NULL
utsname() can return NULL while process is exiting. Kernel releases file locks during process exits. We send request to mds when releasing file lock. So it's possible that we open mds session while process is exiting. utsname() is called in create_session_open_msg(). Link: http://tracker.ceph.com/issues/21275 Signed-off-by: "Yan, Zheng" <[email protected]> Reviewed-by: Jeff Layton <[email protected]> [[email protected]: drop utsname.h include from mds_client.c] Signed-off-by: Ilya Dryomov <[email protected]>
1 parent 29a0cfb commit 717e6f2

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

fs/ceph/mds_client.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
#include <linux/sched.h>
88
#include <linux/debugfs.h>
99
#include <linux/seq_file.h>
10-
#include <linux/utsname.h>
1110
#include <linux/ratelimit.h>
1211

1312
#include "super.h"
@@ -884,8 +883,8 @@ static struct ceph_msg *create_session_open_msg(struct ceph_mds_client *mdsc, u6
884883
void *p;
885884

886885
const char* metadata[][2] = {
887-
{"hostname", utsname()->nodename},
888-
{"kernel_version", utsname()->release},
886+
{"hostname", mdsc->nodename},
887+
{"kernel_version", init_utsname()->release},
889888
{"entity_id", opt->name ? : ""},
890889
{"root", fsopt->server_path ? : "/"},
891890
{NULL, NULL}
@@ -3539,6 +3538,8 @@ int ceph_mdsc_init(struct ceph_fs_client *fsc)
35393538
init_rwsem(&mdsc->pool_perm_rwsem);
35403539
mdsc->pool_perm_tree = RB_ROOT;
35413540

3541+
strncpy(mdsc->nodename, utsname()->nodename,
3542+
sizeof(mdsc->nodename) - 1);
35423543
return 0;
35433544
}
35443545

fs/ceph/mds_client.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include <linux/rbtree.h>
99
#include <linux/spinlock.h>
1010
#include <linux/refcount.h>
11+
#include <linux/utsname.h>
1112

1213
#include <linux/ceph/types.h>
1314
#include <linux/ceph/messenger.h>
@@ -368,6 +369,8 @@ struct ceph_mds_client {
368369

369370
struct rw_semaphore pool_perm_rwsem;
370371
struct rb_root pool_perm_tree;
372+
373+
char nodename[__NEW_UTS_LEN + 1];
371374
};
372375

373376
extern const char *ceph_mds_op_name(int op);

0 commit comments

Comments
 (0)