mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH 0/2] MIPS: rtlx: Fix two error paths in rtlx_open()
@ 2026-11-21 15:33 Suyuan Wang via B4 Relay
  2026-11-21 15:33 ` [PATCH 1/2] MIPS: rtlx: Drop in_open count when rtlx_init() fails Suyuan Wang via B4 Relay
  2026-11-21 15:33 ` [PATCH 2/2] MIPS: rtlx: Call finish_wait() when rtlx_open() is interrupted Suyuan Wang via B4 Relay
  0 siblings, 2 replies; 3+ messages in thread
From: Suyuan Wang via B4 Relay @ 2026-11-21 15:33 UTC (permalink / raw)
  To: tsbogend; +Cc: linux-mips, linux-kernel

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(-)



^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH 1/2] MIPS: rtlx: Drop in_open count when rtlx_init() fails
  2026-11-21 15:33 [PATCH 0/2] MIPS: rtlx: Fix two error paths in rtlx_open() Suyuan Wang via B4 Relay
@ 2026-11-21 15:33 ` Suyuan Wang via B4 Relay
  2026-11-21 15:33 ` [PATCH 2/2] MIPS: rtlx: Call finish_wait() when rtlx_open() is interrupted Suyuan Wang via B4 Relay
  1 sibling, 0 replies; 3+ messages in thread
From: Suyuan Wang via B4 Relay @ 2026-11-21 15:33 UTC (permalink / raw)
  To: tsbogend; +Cc: linux-mips, linux-kernel

From: Suyuan Wang <stevewong@hust.edu.cn>

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.")
Cc: stable@vger.kernel.org
Co-developed-by: Kaixuan Li <kaixuan.li@ntu.edu.sg>
Signed-off-by: Kaixuan Li <kaixuan.li@ntu.edu.sg>
Signed-off-by: Suyuan Wang <stevewong@hust.edu.cn>
---
 arch/mips/kernel/rtlx.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/arch/mips/kernel/rtlx.c b/arch/mips/kernel/rtlx.c
index 18c509c59f33..a1da56163f19 100644
--- a/arch/mips/kernel/rtlx.c
+++ b/arch/mips/kernel/rtlx.c
@@ -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;
 }
 

-- 
2.34.1



^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH 2/2] MIPS: rtlx: Call finish_wait() when rtlx_open() is interrupted
  2026-11-21 15:33 [PATCH 0/2] MIPS: rtlx: Fix two error paths in rtlx_open() Suyuan Wang via B4 Relay
  2026-11-21 15:33 ` [PATCH 1/2] MIPS: rtlx: Drop in_open count when rtlx_init() fails Suyuan Wang via B4 Relay
@ 2026-11-21 15:33 ` Suyuan Wang via B4 Relay
  1 sibling, 0 replies; 3+ messages in thread
From: Suyuan Wang via B4 Relay @ 2026-11-21 15:33 UTC (permalink / raw)
  To: tsbogend; +Cc: linux-mips, linux-kernel

From: Suyuan Wang <stevewong@hust.edu.cn>

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.")
Cc: stable@vger.kernel.org
Co-developed-by: Kaixuan Li <kaixuan.li@ntu.edu.sg>
Signed-off-by: Kaixuan Li <kaixuan.li@ntu.edu.sg>
Signed-off-by: Suyuan Wang <stevewong@hust.edu.cn>
---
 arch/mips/kernel/rtlx.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/arch/mips/kernel/rtlx.c b/arch/mips/kernel/rtlx.c
index a1da56163f19..d5ea99bde129 100644
--- a/arch/mips/kernel/rtlx.c
+++ b/arch/mips/kernel/rtlx.c
@@ -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;
 				}

-- 
2.34.1



^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-11-21 15:33 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-21 15:33 [PATCH 0/2] MIPS: rtlx: Fix two error paths in rtlx_open() Suyuan Wang via B4 Relay
2026-11-21 15:33 ` [PATCH 1/2] MIPS: rtlx: Drop in_open count when rtlx_init() fails Suyuan Wang via B4 Relay
2026-11-21 15:33 ` [PATCH 2/2] MIPS: rtlx: Call finish_wait() when rtlx_open() is interrupted Suyuan Wang via B4 Relay

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®