From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pl1-f170.google.com (mail-pl1-f170.google.com [209.85.214.170]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1546E255F28 for ; Wed, 5 Aug 2026 01:34:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.170 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785893671; cv=none; b=VUoG48qKJtRe3cZmHQ8UeHGXRmteC9NLD7fB+mSj5pcdoAJG8mZT24TY0zr3E0bMReC8wpGiHf71UnBpQIvE2CahT+XKp1/g2TyNe/JpSzWcxhXVAB83eKVeSArKE3uyA2uht6yDzaS+dMa8D/HfuKMPwIfFU/mz+h9a4a1nui8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785893671; c=relaxed/simple; bh=ZjGLWnBgJdXztCi0+eXsQfANXaD3thG2wKtA52T+ocw=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=HmxfJQ4zpeu7RiSTqsV03cfC53febSr008NHvLyR13TS/uhuCYhek0OP549VkhmFo/IvaLxYjwtX/ArYXOWbGHBziRfaJ9DHVoXSXQ5YGjmngWUu0kSt89JHYnoBdzBMuqi9m+uR5QlDphjJMRceDQ717jb7zrDYvlPHvpNkjBs= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=xbow.com; spf=pass smtp.mailfrom=xbow.com; dkim=pass (2048-bit key) header.d=xbow.com header.i=@xbow.com header.b=AJ+itnPq; arc=none smtp.client-ip=209.85.214.170 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=xbow.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=xbow.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=xbow.com header.i=@xbow.com header.b="AJ+itnPq" Received: by mail-pl1-f170.google.com with SMTP id d9443c01a7336-2cc73e322dbso5462985ad.1 for ; Tue, 04 Aug 2026 18:34:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=xbow.com; s=google; t=1785893668; x=1786498468; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to:content-type; bh=5bztIpYgBFdztufOLC4DVVQmB06rOwDY249Dx0zbrkI=; b=AJ+itnPqAXORxylrcM7uT3rtcMGqSdtYgvv8UvOyFQ4Qb5Um+7JZN6rNWihZj6C6pw nSJccEiU2bjds4GCfskMYI5i2PS6zAGhmPIUrhPau5l7C/R6VBPSn3tx7n/6LQWnZJHx pp5V0b6/9DgmaKOIjH35NN3iNIBBkzQKz8ZuAaFzTPDQs01BTu+XhVEBasp60kAEy7k4 /5P1J+zH5kFhNVbpuq/hXHRM1tW//ybN+0W5cRNAuaW4a/twzDPPcoQghwbmWQAfZy6r W1KLyFs6UCNVE8gZ8vAGCqh0w+H4HVaShvMDDEO1kgQNmpMb5Ewdj5sICCGPNrBgSdH4 OY5g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1785893668; x=1786498468; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=5bztIpYgBFdztufOLC4DVVQmB06rOwDY249Dx0zbrkI=; b=CN1zJcQwuJYBBRpkY8AZRKKf6TZQ/f+WjEH6cpUm5GXCGbbMeUJpZqitpYdM65dGHT vTXp75xulNVmR1OxiHPnyqStZD7YobtbO4ZMeUzsJm/hQkbzVOQyq660JsjraJI7OAIo r7uAely69yAYTglv1zYzOQnZCFeas0ChP6oapfUFRcN4H/O7unKF2zcB3fbEE/KV84up t8KOqUdudhEZgdCkE6P+PE1LZJi1kIdHAMu4EuhpmG9P3AwhONTtkqzTAm1a+Adgjv05 M+P5nRJCHmnEZtP189g3/HB79UI7mer2F1N0+uuedAPI30W3S7ra4XIId0q4nd/c6X1X Ameg== X-Forwarded-Encrypted: i=1; AHgh+RrTAcnYf8eppeAnSLiScuMI3t6Uqh7AUhQcFUtOe6KeDJ6eDmxk5rc+iCl0v/DnUyGAh2wstMe1I681mX4=@vger.kernel.org X-Gm-Message-State: AOJu0Yz0GgY5FMH54hpyY6wHBpLhjiEJx0y1UEDW0VON9Lozv0buEfQ5 txt0ESD6tkSU2k0Yw0WzxYTYxMYP4r8TXNM35M2px7GO1eFjCccb1YWFFAZUSh1x4G4= X-Gm-Gg: AR+sD13cjIxK2DGQ+eg19wBUzB+4qDnnaBWH2dDaWazwZ4wBkrUEIIKKGeSVjIADaKE +EfWidYM9ee6nSqJNZ48L6FdexytepMFke5NVnzWgR7hRrfo3xCQk4jsRvy5qaerYePs0CQM8QE 7B2hIYY6l01dZCmJDiqjrC4MkUt3yUR176xSk/tEku0bwJ38Yn/U2knfgk/pT56nZlX9FmEXd9I d1oi5r6R9H7F4eF+DpN5oExTx8hcAsO7ObLHI6CIrr9n3nrX9Am4WDnwxdqadcmHVEN16045CAb qMk87eHDhxPmYiuRInkS+n7bN6ERr/IQ5Y0znKEEFtPlXTzoEBekXInykafll0lPDGTEOWZj25N cLhskKT3oIFcD0eWSDf5e816MNzRYkdon868Z9RvKL1qkTKEVyiFTDLOPFZtaHzFi/5UpnA6Djm Fu4dnli1Hi55oGd0iZxoWxa8wg6KskVJmsPVWKNrBNcJtfTt5smB5NHsTgiWs0DJcF5sVJJLpxL 4CVptYyoeZi5ilAjruv6kjZKXiN X-Received: by 2002:a05:6300:670b:b0:3c0:ac0f:6558 with SMTP id adf61e73a8af0-3cb85e99259mr3406754637.2.1785893668375; Tue, 04 Aug 2026 18:34:28 -0700 (PDT) Received: from Mac.lan ([125.128.148.126]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-cbe707f037dsm457614a12.12.2026.08.04.18.34.25 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Tue, 04 Aug 2026 18:34:28 -0700 (PDT) From: Baul Lee To: perex@perex.cz, tiwai@suse.com Cc: linux-sound@vger.kernel.org, linux-kernel@vger.kernel.org, federico.kirschbaum@xbow.com, stable@vger.kernel.org, Baul Lee Subject: [PATCH] ALSA: 6fire: bound the MIDI event length from the device Date: Wed, 5 Aug 2026 10:34:23 +0900 Message-ID: <20260805013423.38175-1-baul.lee@xbow.com> X-Mailer: git-send-email 2.50.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit usb6fire_comm_receiver_handler() forwards a MIDI event using a length byte the device supplies, with no bound and no check that the transfer delivered that many bytes: if (!urb->status) { if (rt->receiver_buffer[0] == 0x10) /* midi in event */ if (midi_rt) midi_rt->in_received(midi_rt, rt->receiver_buffer + 2, rt->receiver_buffer[1]); } receiver_buffer is a 64-byte kzalloc() buffer (COMM_RECEIVER_BUFSIZE), so only 62 bytes follow the two-byte header. receiver_buffer[1] is a u8 the device chooses, so a device that answers with 0x10 and a length of 0xFF makes snd_rawmidi_receive() read 255 bytes starting two bytes into a 64-byte object. The bytes past the buffer are handed to userspace through the rawmidi read path. urb->actual_length is not consulted either, so a short transfer leaves both the type byte and the length byte at their previous values and the handler acts on stale data. The receiver URB is submitted from usb6fire_comm_init() at probe, so the read happens on plug with no user action; forwarding to userspace also needs a MIDI input substream open, since usb6fire_midi_in_received() only calls snd_rawmidi_receive() when rt->in is set. KASAN on 7.2.0-rc5 (arm64), single packet from an emulated device: BUG: KASAN: slab-out-of-bounds in snd_rawmidi_receive Read of size 255 at addr ffff000009f64682 by task bash/183 __asan_memcpy snd_rawmidi_receive usb6fire_midi_in_received [snd_usb_6fire] usb6fire_comm_receiver_handler [snd_usb_6fire] Allocated by task 11: usb6fire_comm_init [snd_usb_6fire] usb6fire_chip_probe [snd_usb_6fire] The buggy address is located 2 bytes inside of allocated 64-byte region [ffff000009f64680, ffff000009f646c0) Reject the event when the length exceeds the bytes that follow the header, and require the transfer to have delivered the header plus that many bytes. The receiver URB is submitted with a 64-byte transfer_buffer_length, so a genuine device cannot deliver an event longer than those 62 bytes and nothing valid is dropped. Discovered by XBOW, triaged by Baul Lee Fixes: c6d43ba816d1 ("ALSA: usb/6fire - Driver for TerraTec DMX 6Fire USB") Reported-by: Federico Kirschbaum Reported-by: Baul Lee Cc: stable@vger.kernel.org Signed-off-by: Baul Lee --- sound/usb/6fire/comm.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/sound/usb/6fire/comm.c b/sound/usb/6fire/comm.c index 9a0b85653c61..d3b7cab85699 100644 --- a/sound/usb/6fire/comm.c +++ b/sound/usb/6fire/comm.c @@ -33,17 +33,20 @@ static void usb6fire_comm_init_urb(struct comm_runtime *rt, struct urb *urb, static void usb6fire_comm_receiver_handler(struct urb *urb) { struct comm_runtime *rt = urb->context; struct midi_runtime *midi_rt = rt->chip->midi; if (!urb->status) { - if (rt->receiver_buffer[0] == 0x10) /* midi in event */ + u8 len = rt->receiver_buffer[1]; + + if (rt->receiver_buffer[0] == 0x10 && /* midi in event */ + len <= COMM_RECEIVER_BUFSIZE - 2 && + urb->actual_length >= len + 2) if (midi_rt) midi_rt->in_received(midi_rt, - rt->receiver_buffer + 2, - rt->receiver_buffer[1]); + rt->receiver_buffer + 2, len); } if (!rt->chip->shutdown) { urb->status = 0; urb->actual_length = 0; if (usb_submit_urb(urb, GFP_ATOMIC) < 0) -- 2.50.1 (Apple Git-155)