Skip to contentSkip to conversation

liburing: fix shortening api issues

PATCH Applied Dylan Yudaken 3 participants 5 messages Oct 19, 2022 io_uring

lore
Share & tools
lore
#0 lore raw

cover liburing: fix shortening api issues

The liburing public API has a couple of int shortening issues found by compiling with cc="clang -Wshorten-64-to-32 -Werror"

There are a few more in the main library, and a *lot* in the tests, which would be nice to fix up at some point. The public API changes are particularly useful for build systems that include these files and run with these errors enabled.

Dylan Yudaken (2):
fix int shortening bug in io_uring_recvmsg_validate fix len type of fgettxattr etc

 src/include/liburing.h | 23 +++++++++++------------
 1 file changed, 11 insertions(+), 12 deletions(-)

base-commit: 13f3fe3af811d8508676dbd1ef552f2b459e1b21

Signature · 1 line
2.30.2
#1 lore raw

PATCH 1/2 fix int shortening bug in io_uring_recvmsg_validate

Fix for compilers running with -Wshorten-64-to-32

Fixes 874406f7fb09 ("add multishot recvmsg API")
---
 src/include/liburing.h | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
src/include/liburing.h +2 -3
index 1d049230ddfb..118bba9eea15 100644
@@ -791,10 +791,9 @@ static inline void io_uring_prep_recv_multishot(struct io_uring_sqe *sqe,
 static inline struct io_uring_recvmsg_out *
 io_uring_recvmsg_validate(void *buf, int buf_len, struct msghdr *msgh)
 {
-	int header = msgh->msg_controllen + msgh->msg_namelen +
+	unsigned long header = msgh->msg_controllen + msgh->msg_namelen +
 				sizeof(struct io_uring_recvmsg_out);
-
-	if (buf_len < header)
+	if (buf_len < 0 || (unsigned long)buf_len < header)
 		return NULL;
 	return (struct io_uring_recvmsg_out *)buf;
 }
Signature · 1 line
2.30.2
#2 lore raw

PATCH 2/2 fix len type of fgettxattr etc

In reply to Dylan Yudaken

The size_t len was passed to an unsigned int directly.
Take an unsigned int instead which is what is expected by io_uring_prep_rw

Fixes 73849e908ce0 ("liburing: Add helper functions for fgetxattr and getxattr")
Fixes 72f55e271377 ("liburing: add helper functions for setxattr and fsetxattr")
---
 src/include/liburing.h | 18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)
src/include/liburing.h +9 -9
index 118bba9eea15..780a19ccb1d9 100644
@@ -991,7 +991,7 @@ static inline void io_uring_prep_getxattr(struct io_uring_sqe *sqe,
 					  const char *name,
 					  char *value,
 					  const char *path,
-					  size_t len)
+					  unsigned int len)
 {
 	io_uring_prep_rw(IORING_OP_GETXATTR, sqe, 0, name, len,
 				(__u64) (uintptr_t) value);
@@ -1004,7 +1004,7 @@ static inline void io_uring_prep_setxattr(struct io_uring_sqe *sqe,
 					  const char *value,
 					  const char *path,
 					  int flags,
-					  size_t len)
+					  unsigned int len)
 {
 	io_uring_prep_rw(IORING_OP_SETXATTR, sqe, 0, name, len,
 				(__u64) (uintptr_t) value);
@@ -1013,10 +1013,10 @@ static inline void io_uring_prep_setxattr(struct io_uring_sqe *sqe,
 }
 
 static inline void io_uring_prep_fgetxattr(struct io_uring_sqe *sqe,
-		                           int         fd,
+					   int fd,
 					   const char *name,
 					   char *value,
-					   size_t      len)
+					   unsigned int len)
 {
 	io_uring_prep_rw(IORING_OP_FGETXATTR, sqe, fd, name, len,
 				(__u64) (uintptr_t) value);
@@ -1024,11 +1024,11 @@ static inline void io_uring_prep_fgetxattr(struct io_uring_sqe *sqe,
 }
 
 static inline void io_uring_prep_fsetxattr(struct io_uring_sqe *sqe,
-					   int         fd,
-					   const char *name,
-					   const char *value,
-					   int         flags,
-					   size_t      len)
+					   int		fd,
+					   const char	*name,
+					   const char	*value,
+					   int		flags,
+					   unsigned int len)
 {
 	io_uring_prep_rw(IORING_OP_FSETXATTR, sqe, fd, name, len,
 				(__u64) (uintptr_t) value);
Signature · 1 line
2.30.2
maintainer Applied
#3 lore raw
In reply to Dylan Yudaken
Quoted 9 lines · Dylan Yudaken

The liburing public API has a couple of int shortening issues found by compiling with cc="clang -Wshorten-64-to-32 -Werror"

There are a few more in the main library, and a *lot* in the tests, which would be nice to fix up at some point. The public API changes are particularly useful for build systems that include these files and run with these errors enabled.

[...]

Applied, thanks!

[1/2] fix int shortening bug in io_uring_recvmsg_validate

      commit: d916aa80993438dbcec700202b21b550edc03941
[2/2] fix len type of fgettxattr etc
      commit: 5698e179a1308aa8019a482ca910a832b5737e5f

Best regards,

Signature · 1 line
Jens Axboe
#4 lore raw
In reply to Dylan Yudaken
Quoted 7 lines · Dylan Yudaken

The liburing public API has a couple of int shortening issues found by compiling with cc="clang -Wshorten-64-to-32 -Werror"

There are a few more in the main library, and a *lot* in the tests, which would be nice to fix up at some point. The public API changes are particularly useful for build systems that include these files and run with these errors enabled.

Let's clean the main library up, but ignore the tests for now. I'll send a cleanup series for review before the release.

Signature · 1 line
Ammar Faizi