Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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: ebb25defdc17 ("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>

authored by

Christoph Hellwig and committed by
David S. Miller
dfd3d526 aab99b62

+29 -21
+29 -21
net/sctp/socket.c
··· 2749 2749 * timer to expire. The default value for this is 2, setting this 2750 2750 * value to 1 will disable the delayed sack algorithm. 2751 2751 */ 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) 2756 2754 { 2757 2755 struct sctp_sock *sp = sctp_sk(sk); 2758 2756 struct sctp_association *asoc; 2759 - 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 2757 2777 2758 /* Validate value parameter. */ 2778 2759 if (params->sack_delay > 500) ··· 2800 2819 sctp_apply_asoc_delayed_ack(params, asoc); 2801 2820 2802 2821 return 0; 2822 + } 2823 + 2824 + static int sctp_setsockopt_delayed_ack(struct sock *sk, 2825 + struct sctp_sack_info *params, 2826 + unsigned int optlen) 2827 + { 2828 + if (optlen == sizeof(struct sctp_assoc_value)) { 2829 + struct sctp_assoc_value *v = (struct sctp_assoc_value *)params; 2830 + struct sctp_sack_info p; 2831 + 2832 + pr_warn_ratelimited(DEPRECATED 2833 + "%s (pid %d) " 2834 + "Use of struct sctp_assoc_value in delayed_ack socket option.\n" 2835 + "Use struct sctp_sack_info instead\n", 2836 + current->comm, task_pid_nr(current)); 2837 + 2838 + p.sack_assoc_id = v->assoc_id; 2839 + p.sack_delay = v->assoc_value; 2840 + p.sack_freq = v->assoc_value ? 0 : 1; 2841 + return __sctp_setsockopt_delayed_ack(sk, &p); 2842 + } 2843 + 2844 + if (optlen != sizeof(struct sctp_sack_info)) 2845 + return -EINVAL; 2846 + if (params->sack_delay == 0 && params->sack_freq == 0) 2847 + return 0; 2848 + return __sctp_setsockopt_delayed_ack(sk, params); 2803 2849 } 2804 2850 2805 2851 /* 7.1.3 Initialization Parameters (SCTP_INITMSG)