* [PATCH] sctp: copy zeroed stats to user in sctp_getsockopt_pr_streamstatus() when !streamoute
@ 2026-09-19 21:36 Hui Peng
2026-09-24 10:13 ` Paolo Abeni
0 siblings, 1 reply; 3+ messages in thread
From: Hui Peng @ 2026-09-19 21:36 UTC (permalink / raw)
To: marcelo.leitner, lucien.xin, davem, edumazet, kuba, pabeni
Cc: linux-sctp, netdev, linux-kernel
In `sctp_getsockopt_pr_streamstatus()`, when the stream output extension
(`streamoute`) has not yet been allocated for `params.sprstat_sid`, the
function zeroes `params.sprstat_abandoned_unsent` and
`params.sprstat_abandoned_sent`, sets `retval = 0`, and jumps directly
to `out:`, skipping both `put_user(len, optlen)` and
`copy_to_user(optval, ¶ms, len)`.
Consequently, `getsockopt(SCTP_PR_STREAM_STATUS)` returns `0` to
userspace without writing the zeroed statistics into the caller's
`optval` buffer.
Remove the premature `goto out` so the zeroed statistics and `optlen`
are copied to userspace.
Fixes: f952be79cebd ("sctp: introduce struct sctp_stream_out_ext")
Assisted-by: LLM
Signed-off-by: Hui Peng <benquike@gmail.com>
---
net/sctp/socket.c | 8 +++-----
1 file changed, 3 insertions(+), 5 deletions(-)
diff --git a/net/sctp/socket.c b/net/sctp/socket.c
index c7b9e325ec1c..f3e48861e9e6 100644
--- a/net/sctp/socket.c
+++ b/net/sctp/socket.c
@@ -7569,11 +7569,7 @@ static int sctp_getsockopt_pr_streamstatus(struct sock *sk, int len,
/* Not allocated yet, means all stats are 0 */
params.sprstat_abandoned_unsent = 0;
params.sprstat_abandoned_sent = 0;
- retval = 0;
- goto out;
- }
-
- if (policy == SCTP_PR_SCTP_ALL) {
+ } else if (policy == SCTP_PR_SCTP_ALL) {
params.sprstat_abandoned_unsent = 0;
params.sprstat_abandoned_sent = 0;
for (policy = 0; policy <= SCTP_PR_INDEX(MAX); policy++) {
@@ -7589,6 +7585,8 @@ static int sctp_getsockopt_pr_streamstatus(struct sock *sk, int len,
streamoute->abandoned_sent[__SCTP_PR_INDEX(policy)];
}
+ retval = 0;
+
if (put_user(len, optlen) || copy_to_user(optval, ¶ms, len)) {
retval = -EFAULT;
goto out;
--
2.55.0.1082.g2b9226bbc0-goog
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] sctp: copy zeroed stats to user in sctp_getsockopt_pr_streamstatus() when !streamoute
2026-09-19 21:36 [PATCH] sctp: copy zeroed stats to user in sctp_getsockopt_pr_streamstatus() when !streamoute Hui Peng
@ 2026-09-24 10:13 ` Paolo Abeni
2026-09-24 13:44 ` Xin Long
0 siblings, 1 reply; 3+ messages in thread
From: Paolo Abeni @ 2026-09-24 10:13 UTC (permalink / raw)
To: Hui Peng, marcelo.leitner, lucien.xin, davem, edumazet, kuba
Cc: linux-sctp, netdev, linux-kernel
On 9/19/26 23:36, Hui Peng wrote:
> @@ -7589,6 +7585,8 @@ static int sctp_getsockopt_pr_streamstatus(struct sock *sk, int len,
> streamoute->abandoned_sent[__SCTP_PR_INDEX(policy)];
> }
>
> + retval = 0;
> +
AFAICS the above is not needed; retval will be zeroed later, if in case of
no errors.
Also this is IMHO net-next material with no fixes tag.
/P
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] sctp: copy zeroed stats to user in sctp_getsockopt_pr_streamstatus() when !streamoute
2026-09-24 10:13 ` Paolo Abeni
@ 2026-09-24 13:44 ` Xin Long
0 siblings, 0 replies; 3+ messages in thread
From: Xin Long @ 2026-09-24 13:44 UTC (permalink / raw)
To: Paolo Abeni
Cc: Hui Peng, marcelo.leitner, davem, edumazet, kuba, linux-sctp,
netdev, linux-kernel
On Thu, Sep 24, 2026 at 6:14 AM Paolo Abeni <pabeni@redhat.com> wrote:
>
> On 9/19/26 23:36, Hui Peng wrote:
> > @@ -7589,6 +7585,8 @@ static int sctp_getsockopt_pr_streamstatus(struct sock *sk, int len,
> > streamoute->abandoned_sent[__SCTP_PR_INDEX(policy)];
> > }
> >
> > + retval = 0;
> > +
>
> AFAICS the above is not needed; retval will be zeroed later, if in case of
> no errors.
Agree.
>
> Also this is IMHO net-next material with no fixes tag.
>
If users call getsockopt(SCTP_PR_STREAM_STATUS, ¶m) without zeroing
param, the kernel should still initialize the output fields when the call
succeeds (return 0).
So we may think of it as a Fix.
Thanks.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-09-24 13:44 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-09-19 21:36 [PATCH] sctp: copy zeroed stats to user in sctp_getsockopt_pr_streamstatus() when !streamoute Hui Peng
2026-09-24 10:13 ` Paolo Abeni
2026-09-24 13:44 ` Xin Long
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox