From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3849F36AB62 for ; Wed, 28 Jan 2026 17:42:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769622143; cv=none; b=sYxbScJ5/g50NZpHxuWRtNDTa2mhHRsCLoW6Nh7Ni1JbeCOJ76LnI2I4knKbLpXHcVXDwUQlRKfMLdUh8Xf2XCTos+NZ/2Veb2FMpUI+ZlzkxeS5pIOpdqA5YQC8BF9U7LcRy4g0YEbpjAcf9fiDz/kf4JKtYWzclXmaV7KuCF8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769622143; c=relaxed/simple; bh=LhLCnvqqN14Xr7O02GANRON5QpHzmFGF5vjxe8PdhjI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Z7kIYuaBoyVXx2vjwfBKy049Ff6rhUVXw62LSe1au2Z7j2XvDmwc8AWf14zHO89gqypfkWjntMSJzyLngCrsWaHkha99ucjSTcuuDharj2+fX3IAg/4tdZrZ1DhIUKF3dVwTBJIreQy494k7F+DpTGfmi9OXxFHmiUy7NIn3FaQ= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=rBzvs2rI; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="rBzvs2rI" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 537A1C4CEF1; Wed, 28 Jan 2026 17:42:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1769622142; bh=LhLCnvqqN14Xr7O02GANRON5QpHzmFGF5vjxe8PdhjI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=rBzvs2rIlj0XQg8lOBN8s95Hgvg2Nr0J9UFL+g5beKCfRt+nA5xBBgSsOTdQlfAcx UkTh+4iSYUXBlTNZm6+7tB3WjVhljcYWRC4WQXVAUCYLZxZvoZV/FSNfTN3GIaxbcL bGEkQ3/rRyZss2J1qz+kZ/Wk1xV13y/XxDvgcLdPPk/Q9eDU6KN7HWj5DIqsEgk+Ci 2uD/5QgzyUa5TmOzXplxN22Q6+/+Ya8vGS4zoPITz5T10sjwrrcrasVn4Wdreb0qKp O/rHYAAS5LqYc+WDXQ5qhDMFmkPKYqW1K6nF9EfgmN9024yLjxikGMiIRD1Xud/BmJ wVI0wwJqSpY3g== From: Sasha Levin To: stable@vger.kernel.org Cc: Samasth Norway Ananda , Takashi Iwai , Sasha Levin Subject: [PATCH 5.15.y] ALSA: scarlett2: Fix buffer overflow in config retrieval Date: Wed, 28 Jan 2026 12:42:20 -0500 Message-ID: <20260128174220.2597086-1-sashal@kernel.org> X-Mailer: git-send-email 2.51.0 In-Reply-To: <2026012703-wrecking-unpicked-b43c@gregkh> References: <2026012703-wrecking-unpicked-b43c@gregkh> Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Samasth Norway Ananda [ Upstream commit 6f5c69f72e50d51be3a8c028ae7eda42c82902cb ] The scarlett2_usb_get_config() function has a logic error in the endianness conversion code that can cause buffer overflows when count > 1. The code checks `if (size == 2)` where `size` is the total buffer size in bytes, then loops `count` times treating each element as u16 (2 bytes). This causes the loop to access `count * 2` bytes when the buffer only has `size` bytes allocated. Fix by checking the element size (config_item->size) instead of the total buffer size. This ensures the endianness conversion matches the actual element type. Fixes: ac34df733d2d ("ALSA: usb-audio: scarlett2: Update get_config to do endian conversion") Cc: stable@vger.kernel.org Signed-off-by: Samasth Norway Ananda Link: https://patch.msgid.link/20260117012706.1715574-1-samasth.norway.ananda@oracle.com Signed-off-by: Takashi Iwai [ add 32-bit handling block ] Signed-off-by: Sasha Levin --- sound/usb/mixer_scarlett_gen2.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/sound/usb/mixer_scarlett_gen2.c b/sound/usb/mixer_scarlett_gen2.c index 0aa5957cd9f93..87421f92c2761 100644 --- a/sound/usb/mixer_scarlett_gen2.c +++ b/sound/usb/mixer_scarlett_gen2.c @@ -1194,11 +1194,16 @@ static int scarlett2_usb_get_config( err = scarlett2_usb_get(mixer, config_item->offset, buf, size); if (err < 0) return err; - if (size == 2) { + if (config_item->size == 16) { u16 *buf_16 = buf; for (i = 0; i < count; i++, buf_16++) *buf_16 = le16_to_cpu(*(__le16 *)buf_16); + } else if (config_item->size == 32) { + u32 *buf_32 = (u32 *)buf; + + for (i = 0; i < count; i++, buf_32++) + *buf_32 = le32_to_cpu(*(__le32 *)buf_32); } return 0; } -- 2.51.0