Skip to contentSkip to conversation

MIPS: rtlx: Fix two error paths in rtlx_open()

PATCH New Suyuan Wang 1 participant 3 messages Nov 21 MIPS

lore
Share & tools
lore
#0 lore raw

cover MIPS: rtlx: Fix two error paths in rtlx_open()

Two error paths in rtlx_open() leave state behind: a failed rtlx_init() skips the in_open decrement, so the channel stays busy for good, and a signal while waiting for the SP program leaves the stack wait entry on the queue.

Found with a static analysis tool and checked by hand. Compile tested on mips (maltaaprp_defconfig, W=1); I don't have the hardware.

---
Suyuan Wang (2):
MIPS: rtlx: Drop in_open count when rtlx_init() fails
MIPS: rtlx: Call finish_wait() when rtlx_open() is interrupted

 arch/mips/kernel/rtlx.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
#1 lore raw

PATCH 1/2 MIPS: rtlx: Drop in_open count when rtlx_init() fails

From: Suyuan Wang <[email protected]>

rtlx_open() raises channel_wqs[index].in_open at the start and drops it again at out_fail, on both the success and the error paths. When rtlx_init() fails, for example because the SP program has no valid RTLX id, the code jumps to out_ret instead and skips the decrement.

After that, every later open of the channel sees in_open > 1 and fails with -EBUSY, even after a correct SP program is loaded.

Jump to out_fail so the count is dropped, and remove the now unused out_ret label.

Found with a static analysis tool and checked by hand.

Fixes c4c4018b04f9 ("[MIPS] RTLX, VPE: Make open actually atomic.")
---
 arch/mips/kernel/rtlx.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
arch/mips/kernel/rtlx.c +1 -2
index 18c509c59f33..a1da56163f19 100644
@@ -159,7 +159,7 @@ int rtlx_open(int index, int can_sleep)
 
 		ret = rtlx_init(*p);
 		if (ret < 0)
-			goto out_ret;
+			goto out_fail;
 	}
 
 	chan = &rtlx->channel[index];
@@ -175,7 +175,6 @@ int rtlx_open(int index, int can_sleep)
 	atomic_dec(&channel_wqs[index].in_open);
 	smp_mb();
 
-out_ret:
 	return ret;
 }
 
Signature · 1 line
2.34.1
#2 lore raw

PATCH 2/2 MIPS: rtlx: Call finish_wait() when rtlx_open() is interrupted

In reply to Suyuan Wang

From: Suyuan Wang <[email protected]>

While rtlx_open() waits for the SP program, it calls prepare_to_wait() with a wait entry on its own stack. If a signal is pending, it leaves the loop with:

	ret = -ERESTARTSYS;
	goto out_fail;

and skips finish_wait(). The stack wait entry stays on channel_wqs[index].lx_queue after rtlx_open() returns, and the task is still in TASK_INTERRUPTIBLE state. A later wake up of that queue then walks a stale stack entry.

Call finish_wait() before leaving the loop on a signal.

Found with a static analysis tool and checked by hand.

Fixes 9e3468202657 ("[MIPS] RTLX: Don't use volatile; it's fragile.")
---
 arch/mips/kernel/rtlx.c | 2 ++
 1 file changed, 2 insertions(+)
arch/mips/kernel/rtlx.c +2 -0
index a1da56163f19..d5ea99bde129 100644
@@ -138,6 +138,8 @@ int rtlx_open(int index, int can_sleep)
 						schedule();
 						continue;
 					}
+					finish_wait(&channel_wqs[index].lx_queue,
+						    &wait);
 					ret = -ERESTARTSYS;
 					goto out_fail;
 				}
Signature · 1 line
2.34.1