sctp: copy zeroed stats to user in sctp_getsockopt_pr_streamstatus() when !streamoute
Subsystems (3)
PATCH 1/1 sctp: copy zeroed stats to user in sctp_getsockopt_pr_streamstatus() when !streamoute
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.
--- net/sctp/socket.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-)
net/sctp/socket.c +3 -5
@@ -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;
Signature · 1 line
2.55.0.1082.g2b9226bbc0-goog
Paolo Abeni
maintainernet/sctp/socket.c static int sctp_getsockopt_pr_streamstatus(struct sock *sk, int len, · line 7589
Quoted 6 lines · Hui Peng
net/sctp/socket.c +2
-0@@ -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
Xin Long
maintainerQuoted 11 lines · Paolo Abeni
net/sctp/socket.c static int sctp_getsockopt_pr_streamstatus(struct sock *sk, int len, · line 7589
Quoted 6 lines · Hui Peng
net/sctp/socket.c +2
-0@@ -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.
Quoted 3 lines
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.