Skip to content

Commit

Permalink
sctp: make sure stream nums can match optlen in sctp_setsockopt_reset…
Browse files Browse the repository at this point in the history
…_streams

Now in sctp_setsockopt_reset_streams, it only does the check
optlen < sizeof(*params) for optlen. But it's not enough, as
params->srs_number_streams should also match optlen.

If the streams in params->srs_stream_list are less than stream
nums in params->srs_number_streams, later when dereferencing
the stream list, it could cause a slab-out-of-bounds crash, as
reported by syzbot.

This patch is to fix it by also checking the stream numbers in
sctp_setsockopt_reset_streams to make sure at least it's not
greater than the streams in the list.

Fixes: 7f9d68a ("sctp: implement sender-side procedures for SSN Reset Request Parameter")
Reported-by: Dmitry Vyukov <[email protected]>
Signed-off-by: Xin Long <[email protected]>
Acked-by: Marcelo Ricardo Leitner <[email protected]>
Acked-by: Neil Horman <[email protected]>
Signed-off-by: David S. Miller <[email protected]>
  • Loading branch information
lxin authored and davem330 committed Dec 11, 2017
1 parent 8f659a0 commit 2342b8d
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion net/sctp/socket.c
Original file line number Diff line number Diff line change
Expand Up @@ -3891,13 +3891,17 @@ static int sctp_setsockopt_reset_streams(struct sock *sk,
struct sctp_association *asoc;
int retval = -EINVAL;

if (optlen < sizeof(struct sctp_reset_streams))
if (optlen < sizeof(*params))
return -EINVAL;

params = memdup_user(optval, optlen);
if (IS_ERR(params))
return PTR_ERR(params);

if (params->srs_number_streams * sizeof(__u16) >
optlen - sizeof(*params))
goto out;

asoc = sctp_id2assoc(sk, params->srs_assoc_id);
if (!asoc)
goto out;
Expand Down

0 comments on commit 2342b8d

Please sign in to comment.