stable.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
To: stable@vger.kernel.org
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	patches@lists.linux.dev,
	syzbot+47c24ca20a2fa01f082e@syzkaller.appspotmail.com,
	Xin Long <lucien.xin@gmail.com>,
	"David S. Miller" <davem@davemloft.net>,
	Sasha Levin <sashal@kernel.org>
Subject: [PATCH 5.4 15/92] sctp: check send stream number after wait_for_sndbuf
Date: Tue, 18 Apr 2023 14:20:50 +0200	[thread overview]
Message-ID: <20230418120305.320515501@linuxfoundation.org> (raw)
In-Reply-To: <20230418120304.658273364@linuxfoundation.org>

From: Xin Long <lucien.xin@gmail.com>

[ Upstream commit 2584024b23552c00d95b50255e47bd18d306d31a ]

This patch fixes a corner case where the asoc out stream count may change
after wait_for_sndbuf.

When the main thread in the client starts a connection, if its out stream
count is set to N while the in stream count in the server is set to N - 2,
another thread in the client keeps sending the msgs with stream number
N - 1, and waits for sndbuf before processing INIT_ACK.

However, after processing INIT_ACK, the out stream count in the client is
shrunk to N - 2, the same to the in stream count in the server. The crash
occurs when the thread waiting for sndbuf is awake and sends the msg in a
non-existing stream(N - 1), the call trace is as below:

  KASAN: null-ptr-deref in range [0x0000000000000038-0x000000000000003f]
  Call Trace:
   <TASK>
   sctp_cmd_send_msg net/sctp/sm_sideeffect.c:1114 [inline]
   sctp_cmd_interpreter net/sctp/sm_sideeffect.c:1777 [inline]
   sctp_side_effects net/sctp/sm_sideeffect.c:1199 [inline]
   sctp_do_sm+0x197d/0x5310 net/sctp/sm_sideeffect.c:1170
   sctp_primitive_SEND+0x9f/0xc0 net/sctp/primitive.c:163
   sctp_sendmsg_to_asoc+0x10eb/0x1a30 net/sctp/socket.c:1868
   sctp_sendmsg+0x8d4/0x1d90 net/sctp/socket.c:2026
   inet_sendmsg+0x9d/0xe0 net/ipv4/af_inet.c:825
   sock_sendmsg_nosec net/socket.c:722 [inline]
   sock_sendmsg+0xde/0x190 net/socket.c:745

The fix is to add an unlikely check for the send stream number after the
thread wakes up from the wait_for_sndbuf.

Fixes: 5bbbbe32a431 ("sctp: introduce stream scheduler foundations")
Reported-by: syzbot+47c24ca20a2fa01f082e@syzkaller.appspotmail.com
Signed-off-by: Xin Long <lucien.xin@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
 net/sctp/socket.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/net/sctp/socket.c b/net/sctp/socket.c
index c76b40322ac7d..36db659a0f7f4 100644
--- a/net/sctp/socket.c
+++ b/net/sctp/socket.c
@@ -1850,6 +1850,10 @@ static int sctp_sendmsg_to_asoc(struct sctp_association *asoc,
 		err = sctp_wait_for_sndbuf(asoc, &timeo, msg_len);
 		if (err)
 			goto err;
+		if (unlikely(sinfo->sinfo_stream >= asoc->stream.outcnt)) {
+			err = -EINVAL;
+			goto err;
+		}
 	}
 
 	if (sctp_state(asoc, CLOSED)) {
-- 
2.39.2




  parent reply	other threads:[~2023-04-18 12:28 UTC|newest]

Thread overview: 103+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-04-18 12:20 [PATCH 5.4 00/92] 5.4.241-rc1 review Greg Kroah-Hartman
2023-04-18 12:20 ` [PATCH 5.4 01/92] scsi: ses: Handle enclosure with just a primary component gracefully Greg Kroah-Hartman
2023-04-18 12:20 ` [PATCH 5.4 02/92] x86/PCI: Add quirk for AMD XHCI controller that loses MSI-X state in D3hot Greg Kroah-Hartman
2023-04-18 12:20 ` [PATCH 5.4 03/92] cgroup/cpuset: Wake up cpuset_attach_wq tasks in cpuset_cancel_attach() Greg Kroah-Hartman
2023-04-18 12:20 ` [PATCH 5.4 04/92] Revert "treewide: Replace DECLARE_TASKLET() with DECLARE_TASKLET_OLD()" Greg Kroah-Hartman
2023-04-18 12:20 ` [PATCH 5.4 05/92] treewide: Replace DECLARE_TASKLET() with DECLARE_TASKLET_OLD() Greg Kroah-Hartman
2023-04-18 12:20 ` [PATCH 5.4 06/92] smb3: fix problem with null cifs super block with previous patch Greg Kroah-Hartman
2023-04-18 12:20 ` [PATCH 5.4 07/92] pinctrl: amd: Use irqchip template Greg Kroah-Hartman
2023-04-18 12:20 ` [PATCH 5.4 08/92] pinctrl: amd: disable and mask interrupts on probe Greg Kroah-Hartman
2023-04-18 12:20 ` [PATCH 5.4 09/92] pinctrl: amd: Disable and mask interrupts on resume Greg Kroah-Hartman
2023-04-18 12:20 ` [PATCH 5.4 10/92] pwm: cros-ec: Explicitly set .polarity in .get_state() Greg Kroah-Hartman
2023-04-18 12:20 ` [PATCH 5.4 11/92] pwm: sprd: " Greg Kroah-Hartman
2023-04-18 12:20 ` [PATCH 5.4 12/92] wifi: mac80211: fix invalid drv_sta_pre_rcu_remove calls for non-uploaded sta Greg Kroah-Hartman
2023-04-18 12:20 ` [PATCH 5.4 13/92] icmp: guard against too small mtu Greg Kroah-Hartman
2023-04-18 12:20 ` [PATCH 5.4 14/92] net: dont let netpoll invoke NAPI if in xmit context Greg Kroah-Hartman
2023-04-18 12:20 ` Greg Kroah-Hartman [this message]
2023-04-18 12:20 ` [PATCH 5.4 16/92] ipv6: Fix an uninit variable access bug in __ip6_make_skb() Greg Kroah-Hartman
2023-04-18 12:20 ` [PATCH 5.4 17/92] gpio: davinci: Add irq chip flag to skip set wake Greg Kroah-Hartman
2023-04-18 12:20 ` [PATCH 5.4 18/92] sunrpc: only free unix grouplist after RCU settles Greg Kroah-Hartman
2023-04-18 12:20 ` [PATCH 5.4 19/92] NFSD: callback request does not use correct credential for AUTH_SYS Greg Kroah-Hartman
2023-04-18 12:20 ` [PATCH 5.4 20/92] xhci: also avoid the XHCI_ZERO_64B_REGS quirk with a passthrough iommu Greg Kroah-Hartman
2023-04-18 12:20 ` [PATCH 5.4 21/92] USB: serial: cp210x: add Silicon Labs IFS-USB-DATACABLE IDs Greg Kroah-Hartman
2023-04-18 12:20 ` [PATCH 5.4 22/92] usb: typec: altmodes/displayport: Fix configure initial pin assignment Greg Kroah-Hartman
2023-04-18 12:20 ` [PATCH 5.4 23/92] USB: serial: option: add Telit FE990 compositions Greg Kroah-Hartman
2023-04-18 12:20 ` [PATCH 5.4 24/92] USB: serial: option: add Quectel RM500U-CN modem Greg Kroah-Hartman
2023-04-18 12:21 ` [PATCH 5.4 25/92] iio: adc: ti-ads7950: Set `can_sleep` flag for GPIO chip Greg Kroah-Hartman
2023-04-18 12:21 ` [PATCH 5.4 26/92] iio: dac: cio-dac: Fix max DAC write value check for 12-bit Greg Kroah-Hartman
2023-04-18 12:21 ` [PATCH 5.4 27/92] tty: serial: sh-sci: Fix transmit end interrupt handler Greg Kroah-Hartman
2023-04-18 12:21 ` [PATCH 5.4 28/92] tty: serial: sh-sci: Fix Rx on RZ/G2L SCI Greg Kroah-Hartman
2023-04-18 12:21 ` [PATCH 5.4 29/92] tty: serial: fsl_lpuart: avoid checking for transfer complete when UARTCTRL_SBK is asserted in lpuart32_tx_empty Greg Kroah-Hartman
2023-04-18 12:21 ` [PATCH 5.4 30/92] nilfs2: fix potential UAF of struct nilfs_sc_info in nilfs_segctor_thread() Greg Kroah-Hartman
2023-04-18 12:21 ` [PATCH 5.4 31/92] nilfs2: fix sysfs interface lifetime Greg Kroah-Hartman
2023-04-18 12:21 ` [PATCH 5.4 32/92] ALSA: hda/realtek: Add quirk for Clevo X370SNW Greg Kroah-Hartman
2023-04-18 12:21 ` [PATCH 5.4 33/92] perf/core: Fix the same task check in perf_event_set_output Greg Kroah-Hartman
2023-04-18 12:21 ` [PATCH 5.4 34/92] ftrace: Mark get_lock_parent_ip() __always_inline Greg Kroah-Hartman
2023-04-18 12:21 ` [PATCH 5.4 35/92] can: j1939: j1939_tp_tx_dat_new(): fix out-of-bounds memory access Greg Kroah-Hartman
2023-04-18 12:21 ` [PATCH 5.4 36/92] tracing: Free error logs of tracing instances Greg Kroah-Hartman
2023-04-18 12:21 ` [PATCH 5.4 37/92] net_sched: prevent NULL dereference if default qdisc setup failed Greg Kroah-Hartman
2023-04-18 12:21 ` [PATCH 5.4 38/92] drm/panfrost: Fix the panfrost_mmu_map_fault_addr() error path Greg Kroah-Hartman
2023-04-18 12:21 ` [PATCH 5.4 39/92] ring-buffer: Fix race while reader and writer are on the same page Greg Kroah-Hartman
2023-04-18 12:21 ` [PATCH 5.4 40/92] mm/swap: fix swap_info_struct race between swapoff and get_swap_pages() Greg Kroah-Hartman
2023-04-18 12:21 ` [PATCH 5.4 41/92] irqdomain: Look for existing mapping only once Greg Kroah-Hartman
2023-04-18 12:21 ` [PATCH 5.4 42/92] irqdomain: Refactor __irq_domain_alloc_irqs() Greg Kroah-Hartman
2023-04-18 12:21 ` [PATCH 5.4 43/92] irqdomain: Fix mapping-creation race Greg Kroah-Hartman
2023-04-18 12:21 ` [PATCH 5.4 44/92] Revert "pinctrl: amd: Disable and mask interrupts on resume" Greg Kroah-Hartman
2023-04-18 12:21 ` [PATCH 5.4 45/92] ALSA: emu10k1: fix capture interrupt handler unlinking Greg Kroah-Hartman
2023-04-18 12:21 ` [PATCH 5.4 46/92] ALSA: hda/sigmatel: add pin overrides for Intel DP45SG motherboard Greg Kroah-Hartman
2023-04-18 12:21 ` [PATCH 5.4 47/92] ALSA: i2c/cs8427: fix iec958 mixer control deactivation Greg Kroah-Hartman
2023-04-18 12:21 ` [PATCH 5.4 48/92] ALSA: firewire-tascam: add missing unwind goto in snd_tscm_stream_start_duplex() Greg Kroah-Hartman
2023-04-18 12:21 ` [PATCH 5.4 49/92] ALSA: hda/sigmatel: fix S/PDIF out on Intel D*45* motherboards Greg Kroah-Hartman
2023-04-18 12:21 ` [PATCH 5.4 50/92] Bluetooth: L2CAP: Fix use-after-free in l2cap_disconnect_{req,rsp} Greg Kroah-Hartman
2023-04-18 12:21 ` [PATCH 5.4 51/92] Bluetooth: Fix race condition in hidp_session_thread Greg Kroah-Hartman
2023-04-18 12:21 ` [PATCH 5.4 52/92] btrfs: print checksum type and implementation at mount time Greg Kroah-Hartman
2023-04-18 12:21 ` [PATCH 5.4 53/92] btrfs: fix fast csum implementation detection Greg Kroah-Hartman
2023-04-18 12:21 ` [PATCH 5.4 54/92] mtdblock: tolerate corrected bit-flips Greg Kroah-Hartman
2023-04-18 12:21 ` [PATCH 5.4 55/92] mtd: rawnand: meson: fix bitmask for length in command word Greg Kroah-Hartman
2023-04-18 12:21 ` [PATCH 5.4 56/92] mtd: rawnand: stm32_fmc2: remove unsupported EDO mode Greg Kroah-Hartman
2023-04-18 12:21 ` [PATCH 5.4 57/92] 9p/xen : Fix use after free bug in xen_9pfs_front_remove due to race condition Greg Kroah-Hartman
2023-04-18 12:21 ` [PATCH 5.4 58/92] niu: Fix missing unwind goto in niu_alloc_channels() Greg Kroah-Hartman
2023-04-18 12:21 ` [PATCH 5.4 59/92] qlcnic: check pci_reset_function result Greg Kroah-Hartman
2023-04-18 12:21 ` [PATCH 5.4 60/92] sctp: fix a potential overflow in sctp_ifwdtsn_skip Greg Kroah-Hartman
2023-04-18 12:21 ` [PATCH 5.4 61/92] RDMA/core: Fix GID entry ref leak when create_ah fails Greg Kroah-Hartman
2023-04-18 12:21 ` [PATCH 5.4 62/92] udp6: fix potential access to stale information Greg Kroah-Hartman
2023-04-18 12:21 ` [PATCH 5.4 63/92] net: macb: fix a memory corruption in extended buffer descriptor mode Greg Kroah-Hartman
2023-04-18 12:21 ` [PATCH 5.4 64/92] power: supply: cros_usbpd: reclassify "default case!" as debug Greg Kroah-Hartman
2023-04-18 12:21 ` [PATCH 5.4 65/92] i2c: imx-lpi2c: clean rx/tx buffers upon new message Greg Kroah-Hartman
2023-04-18 12:21 ` [PATCH 5.4 66/92] efi: sysfb_efi: Add quirk for Lenovo Yoga Book X91F/L Greg Kroah-Hartman
2023-04-18 12:21 ` [PATCH 5.4 67/92] drm: panel-orientation-quirks: Add quirk for Lenovo Yoga Book X90F Greg Kroah-Hartman
2023-04-18 12:21 ` [PATCH 5.4 68/92] verify_pefile: relax wrapper length check Greg Kroah-Hartman
2023-04-18 12:21 ` [PATCH 5.4 69/92] asymmetric_keys: log on fatal failures in PE/pkcs7 Greg Kroah-Hartman
2023-04-18 12:21 ` [PATCH 5.4 70/92] ubi: Fix failure attaching when vid_hdr offset equals to (sub)page size Greg Kroah-Hartman
2023-04-18 12:21 ` [PATCH 5.4 71/92] mtd: ubi: wl: Fix a couple of kernel-doc issues Greg Kroah-Hartman
2023-04-18 12:21 ` [PATCH 5.4 72/92] ubi: Fix deadlock caused by recursively holding work_sem Greg Kroah-Hartman
2023-04-18 12:21 ` [PATCH 5.4 73/92] i2c: ocores: generate stop condition after timeout in polling mode Greg Kroah-Hartman
2023-04-18 12:21 ` [PATCH 5.4 74/92] watchdog: sbsa_wdog: Make sure the timeout programming is within the limits Greg Kroah-Hartman
2023-04-18 12:21 ` [PATCH 5.4 75/92] coresight-etm4: Fix for() loop drvdata->nr_addr_cmp range bug Greg Kroah-Hartman
2023-04-18 12:21 ` [PATCH 5.4 76/92] xfs: show the proper user quota options Greg Kroah-Hartman
2023-04-18 12:21 ` [PATCH 5.4 77/92] xfs: merge the projid fields in struct xfs_icdinode Greg Kroah-Hartman
2023-04-18 12:21 ` [PATCH 5.4 78/92] xfs: ensure that the inode uid/gid match values match the icdinode ones Greg Kroah-Hartman
2023-04-18 12:21 ` [PATCH 5.4 79/92] xfs: remove the icdinode di_uid/di_gid members Greg Kroah-Hartman
2023-04-18 12:21 ` [PATCH 5.4 80/92] xfs: remove the kuid/kgid conversion wrappers Greg Kroah-Hartman
2023-04-18 12:21 ` [PATCH 5.4 81/92] xfs: add a new xfs_sb_version_has_v3inode helper Greg Kroah-Hartman
2023-04-18 12:21 ` [PATCH 5.4 82/92] xfs: only check the superblock version for dinode size calculation Greg Kroah-Hartman
2023-04-18 12:21 ` [PATCH 5.4 83/92] xfs: simplify di_flags2 inheritance in xfs_ialloc Greg Kroah-Hartman
2023-04-18 12:21 ` [PATCH 5.4 84/92] xfs: simplify a check in xfs_ioctl_setattr_check_cowextsize Greg Kroah-Hartman
2023-04-18 12:22 ` [PATCH 5.4 85/92] xfs: remove the di_version field from struct icdinode Greg Kroah-Hartman
2023-04-18 12:22 ` [PATCH 5.4 86/92] xfs: fix up non-directory creation in SGID directories Greg Kroah-Hartman
2023-04-18 12:22 ` [PATCH 5.4 87/92] xfs: set inode size after creating symlink Greg Kroah-Hartman
2023-04-18 12:22 ` [PATCH 5.4 88/92] xfs: report corruption only as a regular error Greg Kroah-Hartman
2023-04-18 12:22 ` [PATCH 5.4 89/92] xfs: shut down the filesystem if we screw up quota reservation Greg Kroah-Hartman
2023-04-18 12:22 ` [PATCH 5.4 90/92] xfs: consider shutdown in bmapbt cursor delete assert Greg Kroah-Hartman
2023-04-18 12:22 ` [PATCH 5.4 91/92] xfs: dont reuse busy extents on extent trim Greg Kroah-Hartman
2023-04-18 12:22 ` [PATCH 5.4 92/92] xfs: force log and push AIL to clear pinned inodes when aborting mount Greg Kroah-Hartman
2023-04-18 14:12 ` [PATCH 5.4 00/92] 5.4.241-rc1 review Chris Paterson
2023-04-18 16:36 ` Florian Fainelli
2023-04-18 21:28 ` Shuah Khan
2023-04-19  3:34 ` Guenter Roeck
2023-04-19  7:41 ` Naresh Kamboju
2023-04-19  7:58   ` Cyril Hrubis
2023-04-21  8:04     ` Petr Vorel
2023-04-24  6:36       ` Yang Xu (Fujitsu)
2023-04-19 12:37 ` Harshit Mogalapalli
2023-04-19 13:30 ` zhouzhixiu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230418120305.320515501@linuxfoundation.org \
    --to=gregkh@linuxfoundation.org \
    --cc=davem@davemloft.net \
    --cc=lucien.xin@gmail.com \
    --cc=patches@lists.linux.dev \
    --cc=sashal@kernel.org \
    --cc=stable@vger.kernel.org \
    --cc=syzbot+47c24ca20a2fa01f082e@syzkaller.appspotmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).