Received: by 2002:a05:6358:489b:b0:bb:da1:e618 with SMTP id x27csp6772266rwn; Tue, 13 Sep 2022 08:49:46 -0700 (PDT) X-Google-Smtp-Source: AA6agR4tCzkt4/RT1vLhh+rXK4EL1LDM9+o0Ieu32boynFyQ66qJUQcQHDsmzJXveVnAKU6UZFWM X-Received: by 2002:a17:907:743:b0:740:ef93:2ffc with SMTP id xc3-20020a170907074300b00740ef932ffcmr23182364ejb.514.1663084186250; Tue, 13 Sep 2022 08:49:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1663084186; cv=none; d=google.com; s=arc-20160816; b=vtXLUofnu8eG8F4CDyPbFesuNBPFtMHJKGfaZvKdLyaSL2ofjI5H2P1G65SXpM7shP CUgbSyjnSdirE71xXVfCeYXcD94T5qjMLZjUugojkuNrGivKZHLHXcDTaBpCpHCbee3L 89fn2Y0uECFwdY2EORQHRjlJ4lIQO282hAS+vffAPiIlX5nqqNvOuKhwHUvFhJAEBjIw NFi0trwrCFcjP4m7a7IXe+SjzFkTkgmHNbq5UL/fGXNCzRgxmnYPh6DpNPaNhEwcnHMA lig1TFBt3Oh9h7bG7bVTY6meMPUrqXcEHwDQcieStWXEBTCnvw+Z3ewnhn0vno7/2W2c P5fg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=Furdcmy8EkqWLRybiB9+/6lP97/xTvKdUiYsdADlP4s=; b=LHOZWVe8K2kGNftpFe31dWhG6K1ZPKK/CxooUdOfLFIXVYD1AxhmhON4XFoLib0Vr9 QBAtTohbLK1wcPndSzM5XyFd4fjfqtz1Mmrucibj4IKYngdfKA4rwc9I12mGwUst92LK QgRanDvOjuf//rAW3RtXvBh3rhaJYolOK4jCcqSA5BcjzS52xpnq1Vv4uWDsld4at9CV 2ho3v5FXMeBPXt+B/8uq4EHOMpkIAVgPfxrKjMja6ZmbWbd/Gy0eagMT/zTMb1oBfnUC hMI3a5BKtP2OXsuSUaTbJerfSUTEqUNAMPyBpmfDI3bD5EokmxvtHxn+259YKPa/e3MR 563A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=2TxUfLfo; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id e22-20020a17090658d600b00730928be67asi12892737ejs.675.2022.09.13.08.49.19; Tue, 13 Sep 2022 08:49:46 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=2TxUfLfo; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236014AbiIMPWO (ORCPT + 99 others); Tue, 13 Sep 2022 11:22:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49418 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235897AbiIMPVj (ORCPT ); Tue, 13 Sep 2022 11:21:39 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 08B727B2A5; Tue, 13 Sep 2022 07:36:23 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 42086B80FE1; Tue, 13 Sep 2022 14:35:10 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 87577C433C1; Tue, 13 Sep 2022 14:35:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1663079708; bh=9BgiPP6OCpWvSkGqFHD61EJ8AiegDO/o1o7/clXSep4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=2TxUfLfoMnJdS6rbbutrldXM2e0d/J+Mq6Sa2omjUGMcUa4narZ/MSeLHA70MsOZs m0Hbz9RyNxSIziFjQ4hKD0qHaF6pQF5iQ55ybbXL72wxQQ4cm3rSrFDsaWKXlQQkDZ 83mQeRHohbBNeeBrm4UrmVjiBgdFwQt55fMeQL4E= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Tasos Sahanidis , Takashi Iwai Subject: [PATCH 4.14 44/61] ALSA: emu10k1: Fix out of bounds access in snd_emu10k1_pcm_channel_alloc() Date: Tue, 13 Sep 2022 16:07:46 +0200 Message-Id: <20220913140348.674888319@linuxfoundation.org> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20220913140346.422813036@linuxfoundation.org> References: <20220913140346.422813036@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Tasos Sahanidis commit d29f59051d3a07b81281b2df2b8c9dfe4716067f upstream. The voice allocator sometimes begins allocating from near the end of the array and then wraps around, however snd_emu10k1_pcm_channel_alloc() accesses the newly allocated voices as if it never wrapped around. This results in out of bounds access if the first voice has a high enough index so that first_voice + requested_voice_count > NUM_G (64). The more voices are requested, the more likely it is for this to occur. This was initially discovered using PipeWire, however it can be reproduced by calling aplay multiple times with 16 channels: aplay -r 48000 -D plughw:CARD=Live,DEV=3 -c 16 /dev/zero UBSAN: array-index-out-of-bounds in sound/pci/emu10k1/emupcm.c:127:40 index 65 is out of range for type 'snd_emu10k1_voice [64]' CPU: 1 PID: 31977 Comm: aplay Tainted: G W IOE 6.0.0-rc2-emu10k1+ #7 Hardware name: ASUSTEK COMPUTER INC P5W DH Deluxe/P5W DH Deluxe, BIOS 3002 07/22/2010 Call Trace: dump_stack_lvl+0x49/0x63 dump_stack+0x10/0x16 ubsan_epilogue+0x9/0x3f __ubsan_handle_out_of_bounds.cold+0x44/0x49 snd_emu10k1_playback_hw_params+0x3bc/0x420 [snd_emu10k1] snd_pcm_hw_params+0x29f/0x600 [snd_pcm] snd_pcm_common_ioctl+0x188/0x1410 [snd_pcm] ? exit_to_user_mode_prepare+0x35/0x170 ? do_syscall_64+0x69/0x90 ? syscall_exit_to_user_mode+0x26/0x50 ? do_syscall_64+0x69/0x90 ? exit_to_user_mode_prepare+0x35/0x170 snd_pcm_ioctl+0x27/0x40 [snd_pcm] __x64_sys_ioctl+0x95/0xd0 do_syscall_64+0x5c/0x90 ? do_syscall_64+0x69/0x90 ? do_syscall_64+0x69/0x90 entry_SYSCALL_64_after_hwframe+0x63/0xcd Signed-off-by: Tasos Sahanidis Cc: Link: https://lore.kernel.org/r/3707dcab-320a-62ff-63c0-73fc201ef756@tasossah.com Signed-off-by: Takashi Iwai Signed-off-by: Greg Kroah-Hartman --- sound/pci/emu10k1/emupcm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) --- a/sound/pci/emu10k1/emupcm.c +++ b/sound/pci/emu10k1/emupcm.c @@ -137,7 +137,7 @@ static int snd_emu10k1_pcm_channel_alloc epcm->voices[0]->epcm = epcm; if (voices > 1) { for (i = 1; i < voices; i++) { - epcm->voices[i] = &epcm->emu->voices[epcm->voices[0]->number + i]; + epcm->voices[i] = &epcm->emu->voices[(epcm->voices[0]->number + i) % NUM_G]; epcm->voices[i]->epcm = epcm; } }