Skip to contentSkip to conversation

io_uring/register: guard compat syscall with CONFIG_COMPAT

PATCH In review Jens Axboe 2 participants 5 messages Jan 17, 2024 io_uring

lore
Share & tools
lore

Jens Axboe

author maintainer
#0 lore raw

PATCH 1/1 io_uring/register: guard compat syscall with CONFIG_COMPAT

Add compat.h include to avoid a potential build issue:

io_uring/register.c:281:6: error: call to undeclared function 'in_compat_syscall'; ISO C99 and later do not support implicit function declarations [-Werror,-Wimplicit-function-declaration]

if (in_compat_syscall()) {
    ^
1 warning generated.
io_uring/register.c:282:9: error: call to undeclared function 'compat_get_bitmap'; ISO C99 and later do not support implicit function declarations [-Werror,-Wimplicit-function-declaration]
ret = compat_get_bitmap(cpumask_bits(new_mask),
      ^
Fixes c43203154d8a ("io_uring/register: move io_uring_register(2) related code to register.c")

---

io_uring/register.c +5 -3
index 708dd1d89add..5e62c1208996 100644
@@ -14,6 +14,7 @@
 #include <linux/slab.h>
 #include <linux/uaccess.h>
 #include <linux/nospec.h>
+#include <linux/compat.h>
 #include <linux/io_uring.h>
 #include <linux/io_uring_types.h>
 
@@ -278,13 +279,14 @@ static __cold int io_register_iowq_aff(struct io_ring_ctx *ctx,
 	if (len > cpumask_size())
 		len = cpumask_size();
 
-	if (in_compat_syscall()) {
+#ifdef CONFIG_COMPAT
+	if (in_compat_syscall())
 		ret = compat_get_bitmap(cpumask_bits(new_mask),
 					(const compat_ulong_t __user *)arg,
 					len * 8 /* CHAR_BIT */);
-	} else {
+	else
+#endif
 		ret = copy_from_user(new_mask, arg, len);
-	}
 
 	if (ret) {
 		free_cpumask_var(new_mask);
Signature · 1 line
Jens Axboe
#1 lore raw

Hi, Jens,

Quoted 22 lines · Jens Axboe

Add compat.h include to avoid a potential build issue:

io_uring/register.c:281:6: error: call to undeclared function 'in_compat_syscall'; ISO C99 and later do not support implicit function declarations [-Werror,-Wimplicit-function-declaration]

if (in_compat_syscall()) {
    ^
1 warning generated.
io_uring/register.c:282:9: error: call to undeclared function 'compat_get_bitmap'; ISO C99 and later do not support implicit function declarations [-Werror,-Wimplicit-function-declaration]
ret = compat_get_bitmap(cpumask_bits(new_mask),
      ^
Fixes c43203154d8a ("io_uring/register: move io_uring_register(2) related code to register.c")

---

io_uring/register.c +0 -0
index 708dd1d89add..5e62c1208996 100644

io_uring/register.c line 19

Quoted 6 lines
io_uring/register.c +1 -0
@@ -14,6 +14,7 @@
 #include <linux/slab.h>
 #include <linux/uaccess.h>
 #include <linux/nospec.h>
+#include <linux/compat.h>
 #include <linux/io_uring.h>
 #include <linux/io_uring_types.h>

This makes sense to me, but I wasn't able to reproduce that build error after disabling CONFIG_COMPAT.

io_uring/register.c static __cold int io_register_iowq_aff(struct io_ring_ctx *ctx, · line 283

Quoted 7 lines
io_uring/register.c +2 -1
@@ -278,13 +279,14 @@ static __cold int io_register_iowq_aff(struct io_ring_ctx *ctx,
 	if (len > cpumask_size())
 		len = cpumask_size();
 
-	if (in_compat_syscall()) {
+#ifdef CONFIG_COMPAT
+	if (in_compat_syscall())

I don't think this is needed.

linux/compat.h:
...
#else /* !CONFIG_COMPAT */

#define is_compat_task() (0)
/* Ensure no one redefines in_compat_syscall() under !CONFIG_COMPAT */ #define in_compat_syscall in_compat_syscall
static inline bool in_compat_syscall(void) { return false; }

Isn't the code fine as-is?

-Jeff

Quoted 11 lines
io_uring/register.c +2 -2
 		ret = compat_get_bitmap(cpumask_bits(new_mask),
 					(const compat_ulong_t __user *)arg,
 					len * 8 /* CHAR_BIT */);
-	} else {
+	else
+#endif
 		ret = copy_from_user(new_mask, arg, len);
-	}
 
 	if (ret) {
 		free_cpumask_var(new_mask);
author maintainer
#2 lore raw
Quoted 21 lines · Jeff Moyer

Hi, Jens,

Quoted 17 lines · Jens Axboe

Add compat.h include to avoid a potential build issue:

io_uring/register.c:281:6: error: call to undeclared function 'in_compat_syscall'; ISO C99 and later do not support implicit function declarations [-Werror,-Wimplicit-function-declaration]

if (in_compat_syscall()) {
    ^
1 warning generated.
io_uring/register.c:282:9: error: call to undeclared function 'compat_get_bitmap'; ISO C99 and later do not support implicit function declarations [-Werror,-Wimplicit-function-declaration]
ret = compat_get_bitmap(cpumask_bits(new_mask),
      ^
Fixes c43203154d8a ("io_uring/register: move io_uring_register(2) related code to register.c")

---

Quoted 14 lines

io_uring/register.c line 19

Quoted 11 lines
io_uring/register.c +1 -0
index 708dd1d89add..5e62c1208996 100644
@@ -14,6 +14,7 @@
 #include <linux/slab.h>
 #include <linux/uaccess.h>
 #include <linux/nospec.h>
+#include <linux/compat.h>
 #include <linux/io_uring.h>
 #include <linux/io_uring_types.h>

This makes sense to me, but I wasn't able to reproduce that build error after disabling CONFIG_COMPAT.

I couldn't either, but apparently it happened internally with our kdump config variant.

Quoted 14 lines

io_uring/register.c static __cold int io_register_iowq_aff(struct io_ring_ctx *ctx, · line 283

Quoted 7 lines
io_uring/register.c +2 -1
@@ -278,13 +279,14 @@ static __cold int io_register_iowq_aff(struct io_ring_ctx *ctx,
 	if (len > cpumask_size())
 		len = cpumask_size();
 
-	if (in_compat_syscall()) {
+#ifdef CONFIG_COMPAT
+	if (in_compat_syscall())

I don't think this is needed.

linux/compat.h:
...
#else /* !CONFIG_COMPAT */

Quoted 6 lines

#define is_compat_task() (0)
/* Ensure no one redefines in_compat_syscall() under !CONFIG_COMPAT */ #define in_compat_syscall in_compat_syscall
static inline bool in_compat_syscall(void) { return false; }

Isn't the code fine as-is?

It probably is, but this makes it consistent with the other spots we do compat handling. Hence I'd prefer to keep it like that, and then perhaps we can prune them all at some point.

Thanks for taking a look!

Signature · 1 line
Jens Axboe
Reviewed-by
#3 lore raw
Quoted 37 lines · Jens Axboe
Quoted 21 lines · Jeff Moyer

Hi, Jens,

Quoted 17 lines · Jens Axboe

Add compat.h include to avoid a potential build issue:

io_uring/register.c:281:6: error: call to undeclared function 'in_compat_syscall'; ISO C99 and later do not support implicit function declarations [-Werror,-Wimplicit-function-declaration]

if (in_compat_syscall()) {
    ^
1 warning generated.
io_uring/register.c:282:9: error: call to undeclared function 'compat_get_bitmap'; ISO C99 and later do not support implicit function declarations [-Werror,-Wimplicit-function-declaration]
ret = compat_get_bitmap(cpumask_bits(new_mask),
      ^
Fixes c43203154d8a ("io_uring/register: move io_uring_register(2) related code to register.c")

---

Quoted 14 lines

io_uring/register.c line 19

Quoted 11 lines
io_uring/register.c +1 -0
index 708dd1d89add..5e62c1208996 100644
@@ -14,6 +14,7 @@
 #include <linux/slab.h>
 #include <linux/uaccess.h>
 #include <linux/nospec.h>
+#include <linux/compat.h>
 #include <linux/io_uring.h>
 #include <linux/io_uring_types.h>

This makes sense to me, but I wasn't able to reproduce that build error after disabling CONFIG_COMPAT.

Quoted 2 lines

I couldn't either, but apparently it happened internally with our kdump config variant.

ok.

Quoted 19 lines
Quoted 19 lines

io_uring/register.c static __cold int io_register_iowq_aff(struct io_ring_ctx *ctx, · line 283

Quoted 7 lines
io_uring/register.c +2 -1
@@ -278,13 +279,14 @@ static __cold int io_register_iowq_aff(struct io_ring_ctx *ctx,
 	if (len > cpumask_size())
 		len = cpumask_size();
 
-	if (in_compat_syscall()) {
+#ifdef CONFIG_COMPAT
+	if (in_compat_syscall())

I don't think this is needed.

linux/compat.h:
...
#else /* !CONFIG_COMPAT */

#define is_compat_task() (0)
/* Ensure no one redefines in_compat_syscall() under !CONFIG_COMPAT */ #define in_compat_syscall in_compat_syscall
static inline bool in_compat_syscall(void) { return false; }

Quoted 5 lines
Quoted 1 line

Isn't the code fine as-is?

It probably is, but this makes it consistent with the other spots we do compat handling. Hence I'd prefer to keep it like that, and then perhaps we can prune them all at some point.

I see one other spot. :) But if you are happy with it, that's fine by me.

Quoted 1 line

Thanks for taking a look!

Cheers,
Jeff

author maintainer
#4 lore raw
Quoted 19 lines · Jeff Moyer
Quoted 19 lines
Quoted 19 lines

io_uring/register.c static __cold int io_register_iowq_aff(struct io_ring_ctx *ctx, · line 283

Quoted 7 lines
io_uring/register.c +2 -1
@@ -278,13 +279,14 @@ static __cold int io_register_iowq_aff(struct io_ring_ctx *ctx,
 	if (len > cpumask_size())
 		len = cpumask_size();
 
-	if (in_compat_syscall()) {
+#ifdef CONFIG_COMPAT
+	if (in_compat_syscall())

I don't think this is needed.

linux/compat.h:
...
#else /* !CONFIG_COMPAT */

#define is_compat_task() (0)
/* Ensure no one redefines in_compat_syscall() under !CONFIG_COMPAT */ #define in_compat_syscall in_compat_syscall
static inline bool in_compat_syscall(void) { return false; }

Quoted 8 lines
Quoted 5 lines
Quoted 1 line

Isn't the code fine as-is?

It probably is, but this makes it consistent with the other spots we do compat handling. Hence I'd prefer to keep it like that, and then perhaps we can prune them all at some point.

I see one other spot. :) But if you are happy with it, that's fine by me.

I already shipped it internally like that, which is another reason why I'd like to just keep it consistent and then we can do a cleanup on top for 6.9 once tested.

Quoted 3 lines
Quoted 1 line

Thanks for taking a look!

Thanks!

Signature · 1 line
Jens Axboe