Linux s390 Architecture development
 help / color / mirror / Atom feed
* [PATCH net] s390/ctcm: Prevent XID null dereference
@ 2026-08-09 10:55 Aswin Karuvally
  2026-08-10 10:56 ` sashiko-bot
  0 siblings, 1 reply; 2+ messages in thread
From: Aswin Karuvally @ 2026-08-09 10:55 UTC (permalink / raw)
  To: David Miller, Jakub Kicinski, Paolo Abeni, Eric Dumazet,
	Andrew Lunn
  Cc: netdev, linux-s390, Heiko Carstens, Vasily Gorbik,
	Alexander Gordeev, Alexandra Winter, Christian Borntraeger,
	Sven Schnelle, Simon Horman, jeff, stable

The mpc_validate_xid() function sets grp->saved_xid2->xid2_flag2 to 0x40
to signal XID validation error. If peer XID is NULL or r/w channel
pairing mismatch happens, grp->saved_xid2 is never initialized. An
attempt to set the flag in such case leads to NULL dereference.

Fix this by guarding grp->saved_xid2->xid2_flag2 with a NULL check.
Also update mpc_action_go_ready() to treat uninitialized grp->saved_xid2
as validation error.

Fixes: 293d984f0e36 ("ctcm: infrastructure for replaced ctc driver")
Cc: stable@vger.kernel.org
Reviewed-by: Alexandra Winter <wintera@linux.ibm.com>
Signed-off-by: Aswin Karuvally <aswin@linux.ibm.com>
---
 drivers/s390/net/ctcm_mpc.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/drivers/s390/net/ctcm_mpc.c b/drivers/s390/net/ctcm_mpc.c
index aeb102537e7f..a5b55fe6b110 100644
--- a/drivers/s390/net/ctcm_mpc.c
+++ b/drivers/s390/net/ctcm_mpc.c
@@ -826,7 +826,7 @@ static void mpc_action_go_ready(fsm_instance *fsm, int event, void *arg)
 
 	fsm_deltimer(&grp->timer);
 
-	if (grp->saved_xid2->xid2_flag2 == 0x40) {
+	if (!grp->saved_xid2 || grp->saved_xid2->xid2_flag2 == 0x40) {
 		priv->xid->xid2_flag2 = 0x00;
 		if (grp->estconnfunc) {
 			grp->estconnfunc(grp->port_num, 1,
@@ -1636,7 +1636,13 @@ static int mpc_validate_xid(struct mpcg_info *mpcginfo)
 			"The XID used in the MPC protocol is not valid, "
 			"rc = %d\n", rc);
 		priv->xid->xid2_flag2 = 0x40;
-		grp->saved_xid2->xid2_flag2 = 0x40;
+
+		/* If xid is NULL (rc=1) or r/w channel pairing mismatch
+		 * (rc=2) happens, grp->saved_xid2 is never initialized
+		 * and becomes NULL
+		 */
+		if (grp->saved_xid2)
+			grp->saved_xid2->xid2_flag2 = 0x40;
 	}
 
 	return rc;
-- 
2.53.0


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

* Re: [PATCH net] s390/ctcm: Prevent XID null dereference
  2026-08-09 10:55 [PATCH net] s390/ctcm: Prevent XID null dereference Aswin Karuvally
@ 2026-08-10 10:56 ` sashiko-bot
  0 siblings, 0 replies; 2+ messages in thread
From: sashiko-bot @ 2026-08-10 10:56 UTC (permalink / raw)
  To: Aswin Karuvally
  Cc: Alexander Gordeev, Heiko Carstens, Vasily Gorbik, linux-s390

Thank you for your contribution! Sashiko AI review found 5 potential issue(s) to consider:

New issues:
- [High] The XID validation logic creates an asymmetric error handling flaw where a failure on the first processed channel is silently ignored if the second channel succeeds, allowing the group to incorrectly transition to the READY state.

Pre-existing issues:
- [High] Calling `kfree()` on an interior pointer to a previously freed sk_buff data buffer during device teardown.
- [High] An integer underflow when calculating `group_max_buflen` from untrusted network input can lead to a massively oversized buffer limit, potentially causing an `skb_put` panic during transmission.
- [High] Device teardown frees core structures without synchronously cancelling FSM timers, leading to a Use-After-Free.
- [High] Group FSM state is accessed concurrently without locks, leading to data races on shared variables.
--

--- Patch [1]: [PATCH net] s390/ctcm: Prevent XID null dereference ---
commit eba778bf6c3c6c80501b99041bb51b27ad5c49b6
Author: Aswin Karuvally <aswin@linux.ibm.com>
Subject: s390/ctcm: Prevent XID null dereference

The mpc_validate_xid() function sets grp->saved_xid2->xid2_flag2 to 0x40
to signal XID validation error. This commit updates it to prevent a null
dereference if the peer XID is NULL or an r/w channel pairing mismatch
occurs. It also updates mpc_action_go_ready() to handle the uninitialized
structure.

Cc: stable@vger.kernel.org

> diff --git a/drivers/s390/net/ctcm_mpc.c b/drivers/s390/net/ctcm_mpc.c
> --- a/drivers/s390/net/ctcm_mpc.c
> +++ b/drivers/s390/net/ctcm_mpc.c
> @@ -826,7 +826,7 @@ static void mpc_action_go_ready(fsm_instance *fsm, int event, void *arg)
>  
>  	fsm_deltimer(&grp->timer);

[Severity: High]
This is a pre-existing issue, but I am curious about the teardown sequence
when cancelling timers here and during interface removal.

fsm_deltimer() wraps timer_delete(), which doesn't wait for concurrent
timer callbacks to finish.

If a timer expires concurrently during device teardown (ctc_mpc_dealloc_ch)
while the driver proceeds to free grp and grp->fsm, could the executing
timer callback dereference freed memory when it calls fsm_event()?

> -	if (grp->saved_xid2->xid2_flag2 == 0x40) {
> +	if (!grp->saved_xid2 || grp->saved_xid2->xid2_flag2 == 0x40) {

[Severity: High]
If the first channel fails validation (e.g., mismatched direction) and sets
priv->xid->xid2_flag2 to 0x40, grp->saved_xid2 remains NULL.

If the second channel then succeeds, it initializes grp->saved_xid2 with a
valid xid where xid2_flag2 is 0x00. 

Since this check only evaluates grp->saved_xid2->xid2_flag2, could this
allow the state machine to falsely bypass the check and transition to the
ready state, completely ignoring the earlier failure stored in
priv->xid->xid2_flag2?


[Severity: High]
This is a pre-existing issue, but does this state machine implementation
have data races on shared group state variables?

The read and write channels are separate ccw_device instances, so their
irq handlers use different locks. Because fsm_event() dispatches actions
without internal synchronization:

fsm_event()
    state = atomic_read(&fi->state);
    // executes action directly

Can concurrent irq handlers from different channels execute read-modify-write
operations on shared fields (like grp->outstanding_xid2--) simultaneously,
corrupting the state?

>  		priv->xid->xid2_flag2 = 0x00;
>  		if (grp->estconnfunc) {

[ ... ]

> @@ -1636,7 +1636,13 @@ static int mpc_validate_xid(struct mpcg_info *mpcginfo)

[Severity: High]
This is a pre-existing issue, but could the buffer calculation earlier in
mpc_validate_xid() underflow?

mpc_validate_xid() receives an untrusted xid2_buf_len from the network:

    if (grp->group_max_buflen == 0 || grp->group_max_buflen > xid->xid2_buf_len - len)
        grp->group_max_buflen = xid->xid2_buf_len - len;
    
If xid->xid2_buf_len is less than len, does the subtraction underflow to a
huge value?

Since data_space is calculated as grp->group_max_buflen - TH_HEADER_LENGTH
in ctcmpc_chx_txdone(), and skb_put_data() relies on it, can this trigger
an skb_over_panic when packing data into the transmit sk_buff?

>  			"The XID used in the MPC protocol is not valid, "
>  			"rc = %d\n", rc);
>  		priv->xid->xid2_flag2 = 0x40;
> -		grp->saved_xid2->xid2_flag2 = 0x40;
> +
> +		/* If xid is NULL (rc=1) or r/w channel pairing mismatch
> +		 * (rc=2) happens, grp->saved_xid2 is never initialized
> +		 * and becomes NULL
> +		 */
> +		if (grp->saved_xid2)
> +			grp->saved_xid2->xid2_flag2 = 0x40;
>  	}
>  
>  	return rc;

[Severity: High]
This is a pre-existing issue, but I wanted to ask about the lifecycle of
these pointers during teardown. 
    
When the group is initialized:

ctcmpc_init_mpc_group()
    grp->xid = (struct xid2 *)skb_tail_pointer(grp->xid_skb);
    ...
    priv->xid = grp->xid;
    
During device teardown:

ctcm_free_netdevice()
    dev_kfree_skb(grp->xid_skb);
    ...
    kfree(priv->xid);

Does this sequence cause a use-after-free and an invalid free by passing an
interior pointer of the already freed sk_buff data buffer directly to
kfree()?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260809105536.541453-1-aswin@linux.ibm.com?part=1

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

end of thread, other threads:[~2026-08-10 10:56 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-08-09 10:55 [PATCH net] s390/ctcm: Prevent XID null dereference Aswin Karuvally
2026-08-10 10:56 ` sashiko-bot

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