Skip to content

Commit dfd3d52

Browse files
Christoph Hellwigdavem330
authored andcommitted
sctp: fix slab-out-of-bounds in SCTP_DELAYED_SACK processing
This sockopt accepts two kinds of parameters, using struct sctp_sack_info and struct sctp_assoc_value. The mentioned commit didn't notice an implicit cast from the smaller (latter) struct to the bigger one (former) when copying the data from the user space, which now leads to an attempt to write beyond the buffer (because it assumes the storing buffer is bigger than the parameter itself). Fix it by allocating a sctp_sack_info on stack and filling it out based on the small struct for the compat case. Changelog stole from an earlier patch from Marcelo Ricardo Leitner. Fixes: ebb25de ("sctp: pass a kernel pointer to sctp_setsockopt_delayed_ack") Reported-by: syzbot+0e4699d000d8b874d8dc@syzkaller.appspotmail.com Signed-off-by: Christoph Hellwig <hch@lst.de> Acked-by: Marcelo Ricardo Leitner <marcelo.leitner@gmail.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent aab99b6 commit dfd3d52

1 file changed

Lines changed: 29 additions & 21 deletions

File tree

‎net/sctp/socket.c‎

Lines changed: 29 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2749,31 +2749,12 @@ static void sctp_apply_asoc_delayed_ack(struct sctp_sack_info *params,
27492749
* timer to expire. The default value for this is 2, setting this
27502750
* value to 1 will disable the delayed sack algorithm.
27512751
*/
2752-
2753-
static int sctp_setsockopt_delayed_ack(struct sock *sk,
2754-
struct sctp_sack_info *params,
2755-
unsigned int optlen)
2752+
static int __sctp_setsockopt_delayed_ack(struct sock *sk,
2753+
struct sctp_sack_info *params)
27562754
{
27572755
struct sctp_sock *sp = sctp_sk(sk);
27582756
struct sctp_association *asoc;
27592757

2760-
if (optlen == sizeof(struct sctp_sack_info)) {
2761-
if (params->sack_delay == 0 && params->sack_freq == 0)
2762-
return 0;
2763-
} else if (optlen == sizeof(struct sctp_assoc_value)) {
2764-
pr_warn_ratelimited(DEPRECATED
2765-
"%s (pid %d) "
2766-
"Use of struct sctp_assoc_value in delayed_ack socket option.\n"
2767-
"Use struct sctp_sack_info instead\n",
2768-
current->comm, task_pid_nr(current));
2769-
2770-
if (params->sack_delay == 0)
2771-
params->sack_freq = 1;
2772-
else
2773-
params->sack_freq = 0;
2774-
} else
2775-
return -EINVAL;
2776-
27772758
/* Validate value parameter. */
27782759
if (params->sack_delay > 500)
27792760
return -EINVAL;
@@ -2821,6 +2802,33 @@ static int sctp_setsockopt_delayed_ack(struct sock *sk,
28212802
return 0;
28222803
}
28232804

2805+
static int sctp_setsockopt_delayed_ack(struct sock *sk,
2806+
struct sctp_sack_info *params,
2807+
unsigned int optlen)
2808+
{
2809+
if (optlen == sizeof(struct sctp_assoc_value)) {
2810+
struct sctp_assoc_value *v = (struct sctp_assoc_value *)params;
2811+
struct sctp_sack_info p;
2812+
2813+
pr_warn_ratelimited(DEPRECATED
2814+
"%s (pid %d) "
2815+
"Use of struct sctp_assoc_value in delayed_ack socket option.\n"
2816+
"Use struct sctp_sack_info instead\n",
2817+
current->comm, task_pid_nr(current));
2818+
2819+
p.sack_assoc_id = v->assoc_id;
2820+
p.sack_delay = v->assoc_value;
2821+
p.sack_freq = v->assoc_value ? 0 : 1;
2822+
return __sctp_setsockopt_delayed_ack(sk, &p);
2823+
}
2824+
2825+
if (optlen != sizeof(struct sctp_sack_info))
2826+
return -EINVAL;
2827+
if (params->sack_delay == 0 && params->sack_freq == 0)
2828+
return 0;
2829+
return __sctp_setsockopt_delayed_ack(sk, params);
2830+
}
2831+
28242832
/* 7.1.3 Initialization Parameters (SCTP_INITMSG)
28252833
*
28262834
* Applications can specify protocol parameters for the default association

0 commit comments

Comments
 (0)