From: sashiko-bot@kernel.org
To: "Alexander Egorenkov" <egorenar@linux.ibm.com>
Cc: "Alexander Gordeev" <agordeev@linux.ibm.com>,
linux-s390@vger.kernel.org, "Vasily Gorbik" <gor@linux.ibm.com>,
"Heiko Carstens" <hca@linux.ibm.com>
Subject: Re: [PATCH v2 2/2] s390/sclp: Ensure no callback gets called after sclp_unregister() returns
Date: Tue, 04 Aug 2026 08:01:07 +0000 [thread overview]
Message-ID: <20260804080108.4DDF51F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260804074511.236153-3-egorenar@linux.ibm.com>
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] Missing synchronization in sclp_register() error path leads to Use-After-Free.
- [Medium] Concurrent execution of state_change_fn and receiver_fn corrupts the completion mechanism.
--
--- Patch [2]: [PATCH v2 2/2] s390/sclp: Ensure no callback gets called after sclp_unregister() returns ---
commit 56ff5dbe692c5051e8907f572849ceb9402fdda1
Author: Alexander Egorenkov <egorenar@linux.ibm.com>
s390/sclp: Ensure no callback gets called after sclp_unregister() returns
This commit adds a completion mechanism to prevent callbacks from being
executed after a driver unregisters from the SCLP subsystem. It blocks
sclp_unregister() until any inflight state change or receive callbacks
have finished executing.
> It is sufficient to use only one completion per struct sclp_register
> because the callbacks state_change_fn() and receiver_fn() never get called
> in parallel.
[Severity: Medium]
Is this assumption accurate?
Looking at sclp_dispatch_state_change() and sclp_dispatch_evbufs(), both
functions drop sclp_lock before invoking their respective callbacks. If a
driver registers both callbacks (such as sclp_input_event in sclp_tty.c),
could both dispatchers execute concurrently?
If they run in parallel, it seems they would both call reinit_completion()
and complete() on the same reg->done completion, potentially corrupting it
and causing a premature wakeup in sclp_unregister().
> diff --git a/drivers/s390/char/sclp.c b/drivers/s390/char/sclp.c
> index 98e334724a627..8954f4260401b 100644
> --- a/drivers/s390/char/sclp.c
> +++ b/drivers/s390/char/sclp.c
[ ... ]
> @@ -885,6 +890,8 @@ sclp_register(struct sclp_register *reg)
> /* Trigger initial state change callback */
> reg->sclp_receive_mask = 0;
> reg->sclp_send_mask = 0;
> + init_completion(®->done);
> + complete(®->done);
> list_add(®->list, &sclp_reg_list);
> spin_unlock_irqrestore(&sclp_lock, flags);
> rc = sclp_init_mask(1);
[Severity: High]
If sclp_init_mask(1) fails here and returns an error, the listener is removed
from sclp_reg_list and sclp_register() returns the error to the caller.
Since the listener was briefly in the active list, could a hardware interrupt
have started executing the callback concurrently?
If so, does this error path also need to call wait_for_completion(®->done)
before returning? Otherwise, it looks like a concurrently executing callback
could call complete(®->done) on a freed structure if the caller frees the
listener after the registration failure.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260804074511.236153-1-egorenar@linux.ibm.com?part=2
prev parent reply other threads:[~2026-08-04 8:01 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-04 7:45 [PATCH v2 0/2] s390/sclp: Misc fixes Alexander Egorenkov
2026-08-04 7:45 ` [PATCH v2 1/2] s390/sclp_ocf: Fix computation of length of GDS values Alexander Egorenkov
2026-08-04 7:55 ` sashiko-bot
2026-08-04 7:45 ` [PATCH v2 2/2] s390/sclp: Ensure no callback gets called after sclp_unregister() returns Alexander Egorenkov
2026-08-04 8:01 ` sashiko-bot [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260804080108.4DDF51F000E9@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=agordeev@linux.ibm.com \
--cc=egorenar@linux.ibm.com \
--cc=gor@linux.ibm.com \
--cc=hca@linux.ibm.com \
--cc=linux-s390@vger.kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox