diff mbox

[5/5] ceph: avoid null pointer derefernece in case of utsname() return NULL

Message ID 20170912025351.42147-6-zyan@redhat.com (mailing list archive)
State New, archived
Headers show

Commit Message

Yan, Zheng Sept. 12, 2017, 2:53 a.m. UTC
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()

Signed-off-by: "Yan, Zheng" <zyan@redhat.com>
---
 fs/ceph/mds_client.c | 6 ++++--
 fs/ceph/mds_client.h | 3 +++
 2 files changed, 7 insertions(+), 2 deletions(-)

Comments

Jeff Layton Sept. 12, 2017, 1:15 p.m. UTC | #1
On Tue, 2017-09-12 at 10:53 +0800, Yan, Zheng wrote:
> 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()
> 
> Signed-off-by: "Yan, Zheng" <zyan@redhat.com>
> ---
>  fs/ceph/mds_client.c | 6 ++++--
>  fs/ceph/mds_client.h | 3 +++
>  2 files changed, 7 insertions(+), 2 deletions(-)
> 
> diff --git a/fs/ceph/mds_client.c b/fs/ceph/mds_client.c
> index 26893cc1fbee..ab6b998d3f44 100644
> --- a/fs/ceph/mds_client.c
> +++ b/fs/ceph/mds_client.c
> @@ -884,8 +884,8 @@ static struct ceph_msg *create_session_open_msg(struct ceph_mds_client *mdsc, u6
>  	void *p;
>  
>  	const char* metadata[][2] = {
> -		{"hostname", utsname()->nodename},
> -		{"kernel_version", utsname()->release},
> +		{"hostname", mdsc->nodename},
> +		{"kernel_version", init_utsname()->release},
>  		{"entity_id", opt->name ? : ""},
>  		{"root", fsopt->server_path ? : "/"},
>  		{NULL, NULL}
> @@ -3558,6 +3558,8 @@ int ceph_mdsc_init(struct ceph_fs_client *fsc)
>  	init_rwsem(&mdsc->pool_perm_rwsem);
>  	mdsc->pool_perm_tree = RB_ROOT;
>  
> +	strncpy(mdsc->nodename, utsname()->nodename,
> +		sizeof(mdsc->nodename) - 1);
>  	return 0;
>  }
>  
> diff --git a/fs/ceph/mds_client.h b/fs/ceph/mds_client.h
> index db57ae98ed34..636d6b2ec49c 100644
> --- a/fs/ceph/mds_client.h
> +++ b/fs/ceph/mds_client.h
> @@ -8,6 +8,7 @@
>  #include <linux/rbtree.h>
>  #include <linux/spinlock.h>
>  #include <linux/refcount.h>
> +#include <linux/utsname.h>
>  
>  #include <linux/ceph/types.h>
>  #include <linux/ceph/messenger.h>
> @@ -368,6 +369,8 @@ struct ceph_mds_client {
>  
>  	struct rw_semaphore     pool_perm_rwsem;
>  	struct rb_root		pool_perm_tree;
> +
> +	char nodename[__NEW_UTS_LEN + 1];
>  };
>  
>  extern const char *ceph_mds_op_name(int op);

(nit: might want to add a link to the tracker bug in the description)

Reviewed-by: Jeff Layton <jlayton@redhat.com>
--
To unsubscribe from this list: send the line "unsubscribe ceph-devel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/fs/ceph/mds_client.c b/fs/ceph/mds_client.c
index 26893cc1fbee..ab6b998d3f44 100644
--- a/fs/ceph/mds_client.c
+++ b/fs/ceph/mds_client.c
@@ -884,8 +884,8 @@  static struct ceph_msg *create_session_open_msg(struct ceph_mds_client *mdsc, u6
 	void *p;
 
 	const char* metadata[][2] = {
-		{"hostname", utsname()->nodename},
-		{"kernel_version", utsname()->release},
+		{"hostname", mdsc->nodename},
+		{"kernel_version", init_utsname()->release},
 		{"entity_id", opt->name ? : ""},
 		{"root", fsopt->server_path ? : "/"},
 		{NULL, NULL}
@@ -3558,6 +3558,8 @@  int ceph_mdsc_init(struct ceph_fs_client *fsc)
 	init_rwsem(&mdsc->pool_perm_rwsem);
 	mdsc->pool_perm_tree = RB_ROOT;
 
+	strncpy(mdsc->nodename, utsname()->nodename,
+		sizeof(mdsc->nodename) - 1);
 	return 0;
 }
 
diff --git a/fs/ceph/mds_client.h b/fs/ceph/mds_client.h
index db57ae98ed34..636d6b2ec49c 100644
--- a/fs/ceph/mds_client.h
+++ b/fs/ceph/mds_client.h
@@ -8,6 +8,7 @@ 
 #include <linux/rbtree.h>
 #include <linux/spinlock.h>
 #include <linux/refcount.h>
+#include <linux/utsname.h>
 
 #include <linux/ceph/types.h>
 #include <linux/ceph/messenger.h>
@@ -368,6 +369,8 @@  struct ceph_mds_client {
 
 	struct rw_semaphore     pool_perm_rwsem;
 	struct rb_root		pool_perm_tree;
+
+	char nodename[__NEW_UTS_LEN + 1];
 };
 
 extern const char *ceph_mds_op_name(int op);