Skip to contentSkip to conversation

libceph: trivial warning fixes

PATCH In review Ilya Dryomov 2 participants 12 messages May 23, 2017 Ceph common code (libceph)

lore
Share & tools
lore

Ilya Dryomov

author maintainer
#0 lore raw

cover libceph: trivial warning fixes

Hello,

These are fixes for make W=1 warnings reported by Stephen a few days ago.

Thanks,

Ilya

Ilya Dryomov (5):
libceph: use kbasename() and kill ceph_file_part()
libceph: make ceph_msg_data_advance() return void
libceph: drop version variable from ceph_monmap_decode()
libceph: validate blob_struct_v in process_one_ticket()
libceph: fix error handling in process_one_ticket()

 include/linux/ceph/ceph_debug.h |  6 +++---
 net/ceph/auth_x.c               | 13 ++++++++-----
 net/ceph/ceph_common.c          | 13 -------------
 net/ceph/messenger.c            | 11 ++++-------
 net/ceph/mon_client.c           |  4 +---
 5 files changed, 16 insertions(+), 31 deletions(-)
Signature · 1 line
2.4.3
author maintainer
#1 lore raw

PATCH 1/5 libceph: use kbasename() and kill ceph_file_part()

---
 include/linux/ceph/ceph_debug.h |  6 +++---
 net/ceph/ceph_common.c          | 13 -------------
 2 files changed, 3 insertions(+), 16 deletions(-)
include/linux/ceph/ceph_debug.h +3 -3
index aa2e19182d99..51c5bd64bd00 100644
@@ -3,6 +3,8 @@
 
 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
 
+#include <linux/string.h>
+
 #ifdef CONFIG_CEPH_LIB_PRETTYDEBUG
 
 /*
@@ -12,12 +14,10 @@
  */
 
 # if defined(DEBUG) || defined(CONFIG_DYNAMIC_DEBUG)
-extern const char *ceph_file_part(const char *s, int len);
 #  define dout(fmt, ...)						\
 	pr_debug("%.*s %12.12s:%-4d : " fmt,				\
 		 8 - (int)sizeof(KBUILD_MODNAME), "    ",		\
-		 ceph_file_part(__FILE__, sizeof(__FILE__)),		\
-		 __LINE__, ##__VA_ARGS__)
+		 kbasename(__FILE__), __LINE__, ##__VA_ARGS__)
 # else
 /* faux printk call just to see any compiler warnings. */
 #  define dout(fmt, ...)	do {				\
net/ceph/ceph_common.c +0 -13
index 4fd02831beed..47e94b560ba0 100644
@@ -56,19 +56,6 @@ static const struct kernel_param_ops param_ops_supported_features = {
 module_param_cb(supported_features, &param_ops_supported_features, NULL,
 		S_IRUGO);
 
-/*
- * find filename portion of a path (/foo/bar/baz -> baz)
- */
-const char *ceph_file_part(const char *s, int len)
-{
-	const char *e = s + len;
-
-	while (e != s && *(e-1) != '/')
-		e--;
-	return e;
-}
-EXPORT_SYMBOL(ceph_file_part);
-
 const char *ceph_msg_type_name(int type)
 {
 	switch (type) {
Signature · 1 line
2.4.3
Reviewed-by on v1 1/5
#2 lore raw

Re: [PATCH 1/5] libceph: use kbasename() and kill ceph_file_part()

Quoted 1 line · Ilya Dryomov

Looks good.

Quoted 57 lines
---
 include/linux/ceph/ceph_debug.h |  6 +++---
 net/ceph/ceph_common.c          | 13 -------------
 2 files changed, 3 insertions(+), 16 deletions(-)
include/linux/ceph/ceph_debug.h +3 -3
index aa2e19182d99..51c5bd64bd00 100644
@@ -3,6 +3,8 @@
 
 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
 
+#include <linux/string.h>
+
 #ifdef CONFIG_CEPH_LIB_PRETTYDEBUG
 
 /*
@@ -12,12 +14,10 @@
  */
 
 # if defined(DEBUG) || defined(CONFIG_DYNAMIC_DEBUG)
-extern const char *ceph_file_part(const char *s, int len);
 #  define dout(fmt, ...)						\
 	pr_debug("%.*s %12.12s:%-4d : " fmt,				\
 		 8 - (int)sizeof(KBUILD_MODNAME), "    ",		\
-		 ceph_file_part(__FILE__, sizeof(__FILE__)),		\
-		 __LINE__, ##__VA_ARGS__)
+		 kbasename(__FILE__), __LINE__, ##__VA_ARGS__)
 # else
 /* faux printk call just to see any compiler warnings. */
 #  define dout(fmt, ...)	do {				\
net/ceph/ceph_common.c +0 -13
index 4fd02831beed..47e94b560ba0 100644
@@ -56,19 +56,6 @@ static const struct kernel_param_ops param_ops_supported_features = {
 module_param_cb(supported_features, &param_ops_supported_features, NULL,
 		S_IRUGO);
 
-/*
- * find filename portion of a path (/foo/bar/baz -> baz)
- */
-const char *ceph_file_part(const char *s, int len)
-{
-	const char *e = s + len;
-
-	while (e != s && *(e-1) != '/')
-		e--;
-	return e;
-}
-EXPORT_SYMBOL(ceph_file_part);
-
 const char *ceph_msg_type_name(int type)
 {
 	switch (type) {
author maintainer
#3 lore raw

PATCH 2/5 libceph: make ceph_msg_data_advance() return void

In reply to Ilya Dryomov

Both callers ignore the returned bool.

---
 net/ceph/messenger.c | 11 ++++-------
 1 file changed, 4 insertions(+), 7 deletions(-)
net/ceph/messenger.c +4 -7
index 5766a6c896c4..d7ab481b2508 100644
@@ -1174,8 +1174,8 @@ static struct page *ceph_msg_data_next(struct ceph_msg_data_cursor *cursor,
  * Returns true if the result moves the cursor on to the next piece
  * of the data item.
  */
-static bool ceph_msg_data_advance(struct ceph_msg_data_cursor *cursor,
-				size_t bytes)
+static void ceph_msg_data_advance(struct ceph_msg_data_cursor *cursor,
+				  size_t bytes)
 {
 	bool new_piece;
 
@@ -1207,8 +1207,6 @@ static bool ceph_msg_data_advance(struct ceph_msg_data_cursor *cursor,
 		new_piece = true;
 	}
 	cursor->need_crc = new_piece;
-
-	return new_piece;
 }
 
 static size_t sizeof_footer(struct ceph_connection *con)
@@ -1577,7 +1575,6 @@ static int write_partial_message_data(struct ceph_connection *con)
 		size_t page_offset;
 		size_t length;
 		bool last_piece;
-		bool need_crc;
 		int ret;
 
 		page = ceph_msg_data_next(cursor, &page_offset, &length,
@@ -1592,7 +1589,7 @@ static int write_partial_message_data(struct ceph_connection *con)
 		}
 		if (do_datacrc && cursor->need_crc)
 			crc = ceph_crc32c_page(crc, page, page_offset, length);
-		need_crc = ceph_msg_data_advance(cursor, (size_t)ret);
+		ceph_msg_data_advance(cursor, (size_t)ret);
 	}
 
 	dout("%s %p msg %p done\n", __func__, con, msg);
@@ -2299,7 +2296,7 @@ static int read_partial_msg_data(struct ceph_connection *con)
 
 		if (do_datacrc)
 			crc = ceph_crc32c_page(crc, page, page_offset, ret);
-		(void) ceph_msg_data_advance(cursor, (size_t)ret);
+		ceph_msg_data_advance(cursor, (size_t)ret);
 	}
 	if (do_datacrc)
 		con->in_data_crc = crc;
Signature · 1 line
2.4.3
Reviewed-by on v1 2/5
#4 lore raw

Re: [PATCH 2/5] libceph: make ceph_msg_data_advance() return void

Quoted 3 lines · Ilya Dryomov

Both callers ignore the returned bool.

I think the return value may have been used at one time (perhaps even before the original got committed), but since it's not now, this is good.

Quoted 55 lines
---
 net/ceph/messenger.c | 11 ++++-------
 1 file changed, 4 insertions(+), 7 deletions(-)
net/ceph/messenger.c +4 -7
index 5766a6c896c4..d7ab481b2508 100644
@@ -1174,8 +1174,8 @@ static struct page *ceph_msg_data_next(struct ceph_msg_data_cursor *cursor,
  * Returns true if the result moves the cursor on to the next piece
  * of the data item.
  */
-static bool ceph_msg_data_advance(struct ceph_msg_data_cursor *cursor,
-				size_t bytes)
+static void ceph_msg_data_advance(struct ceph_msg_data_cursor *cursor,
+				  size_t bytes)
 {
 	bool new_piece;
 
@@ -1207,8 +1207,6 @@ static bool ceph_msg_data_advance(struct ceph_msg_data_cursor *cursor,
 		new_piece = true;
 	}
 	cursor->need_crc = new_piece;
-
-	return new_piece;
 }
 
 static size_t sizeof_footer(struct ceph_connection *con)
@@ -1577,7 +1575,6 @@ static int write_partial_message_data(struct ceph_connection *con)
 		size_t page_offset;
 		size_t length;
 		bool last_piece;
-		bool need_crc;
 		int ret;
 
 		page = ceph_msg_data_next(cursor, &page_offset, &length,
@@ -1592,7 +1589,7 @@ static int write_partial_message_data(struct ceph_connection *con)
 		}
 		if (do_datacrc && cursor->need_crc)
 			crc = ceph_crc32c_page(crc, page, page_offset, length);
-		need_crc = ceph_msg_data_advance(cursor, (size_t)ret);
+		ceph_msg_data_advance(cursor, (size_t)ret);
 	}
 
 	dout("%s %p msg %p done\n", __func__, con, msg);
@@ -2299,7 +2296,7 @@ static int read_partial_msg_data(struct ceph_connection *con)
 
 		if (do_datacrc)
 			crc = ceph_crc32c_page(crc, page, page_offset, ret);
-		(void) ceph_msg_data_advance(cursor, (size_t)ret);
+		ceph_msg_data_advance(cursor, (size_t)ret);
 	}
 	if (do_datacrc)
 		con->in_data_crc = crc;
author maintainer
#5 lore raw

PATCH 3/5 libceph: drop version variable from ceph_monmap_decode()

In reply to Ilya Dryomov

It's set but not used: CEPH_FEATURE_MONNAMES feature bit isn't advertised, which guarantees a v1 MonMap.

---
 net/ceph/mon_client.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
net/ceph/mon_client.c +1 -3
index 29a0ef351c5e..250f11f78609 100644
@@ -43,15 +43,13 @@ struct ceph_monmap *ceph_monmap_decode(void *p, void *end)
 	int i, err = -EINVAL;
 	struct ceph_fsid fsid;
 	u32 epoch, num_mon;
-	u16 version;
 	u32 len;
 
 	ceph_decode_32_safe(&p, end, len, bad);
 	ceph_decode_need(&p, end, len, bad);
 
 	dout("monmap_decode %p %p len %d\n", p, end, (int)(end-p));
-
-	ceph_decode_16_safe(&p, end, version, bad);
+	p += sizeof(u16);  /* skip version */
 
 	ceph_decode_need(&p, end, sizeof(fsid) + 2*sizeof(u32), bad);
 	ceph_decode_copy(&p, &fsid, sizeof(fsid));
Signature · 1 line
2.4.3
Reviewed-by on v1 3/5
#6 lore raw

Re: [PATCH 3/5] libceph: drop version variable from ceph_monmap_decode()

Quoted 4 lines · Ilya Dryomov

It's set but not used: CEPH_FEATURE_MONNAMES feature bit isn't advertised, which guarantees a v1 MonMap.

Looks good.

Quoted 26 lines
---
 net/ceph/mon_client.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
net/ceph/mon_client.c +1 -3
index 29a0ef351c5e..250f11f78609 100644
@@ -43,15 +43,13 @@ struct ceph_monmap *ceph_monmap_decode(void *p, void *end)
 	int i, err = -EINVAL;
 	struct ceph_fsid fsid;
 	u32 epoch, num_mon;
-	u16 version;
 	u32 len;
 
 	ceph_decode_32_safe(&p, end, len, bad);
 	ceph_decode_need(&p, end, len, bad);
 
 	dout("monmap_decode %p %p len %d\n", p, end, (int)(end-p));
-
-	ceph_decode_16_safe(&p, end, version, bad);
+	p += sizeof(u16);  /* skip version */
 
 	ceph_decode_need(&p, end, sizeof(fsid) + 2*sizeof(u32), bad);
 	ceph_decode_copy(&p, &fsid, sizeof(fsid));
author maintainer
#7 lore raw

PATCH 4/5 libceph: validate blob_struct_v in process_one_ticket()

In reply to Ilya Dryomov

None of these are validated in userspace, but since we do validate reply_struct_v in ceph_x_proc_ticket_reply(), tkt_struct_v (first) and CephXServiceTicket struct_v (second) in process_one_ticket(), validate CephXTicketBlob struct_v as well.

---
 net/ceph/auth_x.c | 3 +++
 1 file changed, 3 insertions(+)
net/ceph/auth_x.c +3 -0
index 2034fb926670..d0126df33f1f 100644
@@ -215,6 +215,9 @@ static int process_one_ticket(struct ceph_auth_client *ac,
 	dout(" ticket blob is %d bytes\n", dlen);
 	ceph_decode_need(ptp, tpend, 1 + sizeof(u64), bad);
 	blob_struct_v = ceph_decode_8(ptp);
+	if (blob_struct_v != 1)
+		goto bad;
+
 	new_secret_id = ceph_decode_64(ptp);
 	ret = ceph_decode_buffer(&new_ticket_blob, ptp, tpend);
 	if (ret)
Signature · 1 line
2.4.3
Reviewed-by on v1 4/5
#8 lore raw

Re: [PATCH 4/5] libceph: validate blob_struct_v in process_one_ticket()

Quoted 6 lines · Ilya Dryomov

None of these are validated in userspace, but since we do validate reply_struct_v in ceph_x_proc_ticket_reply(), tkt_struct_v (first) and CephXServiceTicket struct_v (second) in process_one_ticket(), validate CephXTicketBlob struct_v as well.

Looks good. (I don't know what's valid but I know you do.)

Quoted 19 lines
---
 net/ceph/auth_x.c | 3 +++
 1 file changed, 3 insertions(+)
net/ceph/auth_x.c +3 -0
index 2034fb926670..d0126df33f1f 100644
@@ -215,6 +215,9 @@ static int process_one_ticket(struct ceph_auth_client *ac,
 	dout(" ticket blob is %d bytes\n", dlen);
 	ceph_decode_need(ptp, tpend, 1 + sizeof(u64), bad);
 	blob_struct_v = ceph_decode_8(ptp);
+	if (blob_struct_v != 1)
+		goto bad;
+
 	new_secret_id = ceph_decode_64(ptp);
 	ret = ceph_decode_buffer(&new_ticket_blob, ptp, tpend);
 	if (ret)
author maintainer
#9 lore raw

Re: [PATCH 4/5] libceph: validate blob_struct_v in process_one_ticket()

Quoted 9 lines · Alex Elder
Quoted 6 lines · Ilya Dryomov

None of these are validated in userspace, but since we do validate reply_struct_v in ceph_x_proc_ticket_reply(), tkt_struct_v (first) and CephXServiceTicket struct_v (second) in process_one_ticket(), validate CephXTicketBlob struct_v as well.

Looks good. (I don't know what's valid but I know you do.)

All those auth structs are v1. Thanks for the review!

Ilya

author maintainer
#10 lore raw

PATCH 5/5 libceph: fix error handling in process_one_ticket()

In reply to Ilya Dryomov

Don't leak key internals after new_session_key is populated.

---
 net/ceph/auth_x.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
net/ceph/auth_x.c +5 -5
index d0126df33f1f..8757fb87dab8 100644
@@ -151,7 +151,7 @@ static int process_one_ticket(struct ceph_auth_client *ac,
 	struct timespec validity;
 	void *tp, *tpend;
 	void **ptp;
-	struct ceph_crypto_key new_session_key;
+	struct ceph_crypto_key new_session_key = { 0 };
 	struct ceph_buffer *new_ticket_blob;
 	unsigned long new_expires, new_renew_after;
 	u64 new_secret_id;
@@ -237,13 +237,13 @@ static int process_one_ticket(struct ceph_auth_client *ac,
 	     type, ceph_entity_type_name(type), th->secret_id,
 	     (int)th->ticket_blob->vec.iov_len);
 	xi->have_keys |= th->service;
-
-out:
-	return ret;
+	return 0;
 
 bad:
 	ret = -EINVAL;
-	goto out;
+out:
+	ceph_crypto_key_destroy(&new_session_key);
+	return ret;
 }
 
 static int ceph_x_proc_ticket_reply(struct ceph_auth_client *ac,
Signature · 1 line
2.4.3
Reviewed-by on v1 5/5
#11 lore raw

Re: [PATCH 5/5] libceph: fix error handling in process_one_ticket()

Quoted 3 lines · Ilya Dryomov

Don't leak key internals after new_session_key is populated.

Hmmm. This is a good change. Perhaps ceph_crypto_key_destroy() could zero the pointed-to ceph_crypto_key?

Anyway, this looks good.

Quoted 36 lines
---
 net/ceph/auth_x.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
net/ceph/auth_x.c +5 -5
index d0126df33f1f..8757fb87dab8 100644
@@ -151,7 +151,7 @@ static int process_one_ticket(struct ceph_auth_client *ac,
 	struct timespec validity;
 	void *tp, *tpend;
 	void **ptp;
-	struct ceph_crypto_key new_session_key;
+	struct ceph_crypto_key new_session_key = { 0 };
 	struct ceph_buffer *new_ticket_blob;
 	unsigned long new_expires, new_renew_after;
 	u64 new_secret_id;
@@ -237,13 +237,13 @@ static int process_one_ticket(struct ceph_auth_client *ac,
 	     type, ceph_entity_type_name(type), th->secret_id,
 	     (int)th->ticket_blob->vec.iov_len);
 	xi->have_keys |= th->service;
-
-out:
-	return ret;
+	return 0;
 
 bad:
 	ret = -EINVAL;
-	goto out;
+out:
+	ceph_crypto_key_destroy(&new_session_key);
+	return ret;
 }
 
 static int ceph_x_proc_ticket_reply(struct ceph_auth_client *ac,