Skip to contentSkip to conversation

x86/process: Return early on NULL iobm in native_tss_update_io_bitmap()

PATCH In review lirongqing 2 participants 4 messages Jun 1 – Jun 12 x86

lore
Share & tools
lore

lirongqing

author
#0 lore raw

PATCH 1/1 x86/process: Return early on NULL iobm in native_tss_update_io_bitmap()

From: Li RongQing <[email protected]>

When 'iobm' is NULL, native_tss_update_io_bitmap() clears the thread flag and invalidates the TSS bitmap, but falls through to subsequent code that dereferences 'iobm'.

Add a missing return statement to prevent a potential kernel NULL pointer dereference panic.

---
 arch/x86/kernel/process.c | 1 +
 1 file changed, 1 insertion(+)
arch/x86/kernel/process.c +1 -0
index 4c718f8..d5cd217 100644
@@ -486,6 +486,7 @@ void native_tss_update_io_bitmap(void)
 		if (WARN_ON_ONCE(!iobm)) {
 			clear_thread_flag(TIF_IO_BITMAP);
 			native_tss_invalidate_io_bitmap();
+			return;
 		}
 
 		/*
Signature · 1 line
2.9.4
#1 lore raw
Quoted 19 lines

From: Li RongQing <[email protected]>

When 'iobm' is NULL, native_tss_update_io_bitmap() clears the thread flag and invalidates the TSS bitmap, but falls through to subsequent code that dereferences 'iobm'.

Add a missing return statement to prevent a potential kernel NULL pointer dereference panic.

---
 arch/x86/kernel/process.c | 1 +
 1 file changed, 1 insertion(+)
arch/x86/kernel/process.c index renamed from arch/x86/kernel/process.c +0 -0

4c718f8..d5cd217 100644

arch/x86/kernel/process.c void native_tss_update_io_bitmap(void) · line 491

Quoted 6 lines
arch/x86/kernel/process.c +1 -0
@@ -486,6 +486,7 @@ void native_tss_update_io_bitmap(void)
 		if (WARN_ON_ONCE(!iobm)) {
 			clear_thread_flag(TIF_IO_BITMAP);
 			native_tss_invalidate_io_bitmap();
+			return;
 		}
 

Ping

[Li,Rongqing]

Quoted 3 lines
arch/x86/kernel/process.c +0 -1
 		/*
--

2.9.4

Reviewed-by on v1 1/1
#2 lore raw
In reply to lirongqing

How about?

x86/process: Return early if TIF_IO_BITMAP is set but no IO bitmap is assigned

Quoted 6 lines · lirongqing

From: Li RongQing <[email protected]>

When 'iobm' is NULL, native_tss_update_io_bitmap() clears the thread flag and invalidates the TSS bitmap, but falls through to subsequent code that dereferences 'iobm'.

"When iobm is NULL.." makes it sound like this can easily happen. Would it be better to say:

Outside the IOPL emulation path, the IO bitmap is always expected to be allocated when TIF_IO_BITMAP is set. The paranoid WARN_ON_ONCE() handles the case where the flag and the pointer got out of sync. In this rare scenario, return early instead of continuing and dereferencing a NULL pointer.

Quoted 8 lines

Add a missing return statement to prevent a potential kernel NULL pointer dereference panic.

---
 arch/x86/kernel/process.c | 1 +
 1 file changed, 1 insertion(+)

The code change looks good to me.

Quoted 12 lines
arch/x86/kernel/process.c +1 -0
index 4c718f8..d5cd217 100644
@@ -486,6 +486,7 @@ void native_tss_update_io_bitmap(void)
 		if (WARN_ON_ONCE(!iobm)) {
 			clear_thread_flag(TIF_IO_BITMAP);
 			native_tss_invalidate_io_bitmap();
+			return;
 		}
 
 		/*
#3 lore raw
Quoted 10 lines

How about?

x86/process: Return early if TIF_IO_BITMAP is set but no IO bitmap is assigned

Quoted 2 lines · lirongqing

From: Li RongQing <[email protected]>

Quoted 7 lines
Quoted 4 lines

When 'iobm' is NULL, native_tss_update_io_bitmap() clears the thread flag and invalidates the TSS bitmap, but falls through to subsequent code that dereferences 'iobm'.

"When iobm is NULL.." makes it sound like this can easily happen. Would it be better to say:

True, I haven’t observed this issue myself. I agree that your commit message is better, so I will send a v2 with it.

Thanks

-Li

Quoted 32 lines

Outside the IOPL emulation path, the IO bitmap is always expected to be allocated when TIF_IO_BITMAP is set. The paranoid WARN_ON_ONCE() handles the case where the flag and the pointer got out of sync. In this rare scenario, return early instead of continuing and dereferencing a NULL pointer.

Quoted 8 lines

Add a missing return statement to prevent a potential kernel NULL pointer dereference panic.

---
 arch/x86/kernel/process.c | 1 +
 1 file changed, 1 insertion(+)

The code change looks good to me.

Quoted 12 lines
arch/x86/kernel/process.c +1 -0
index 4c718f8..d5cd217 100644
@@ -486,6 +486,7 @@ void native_tss_update_io_bitmap(void)
 		if (WARN_ON_ONCE(!iobm)) {
 			clear_thread_flag(TIF_IO_BITMAP);
 			native_tss_invalidate_io_bitmap();
+			return;
 		}
 
 		/*