Received: by 2002:a05:6358:489b:b0:bb:da1:e618 with SMTP id x27csp6755762rwn; Tue, 13 Sep 2022 08:36:14 -0700 (PDT) X-Google-Smtp-Source: AA6agR6BMKhu4IqSNKja0wH8UDJFnkRxnBFiK1J319pHPvTvC9ZVl2icnxX1O9oZ36qzhiIHqfS/ X-Received: by 2002:a17:902:ab8d:b0:172:9382:4d1e with SMTP id f13-20020a170902ab8d00b0017293824d1emr32031954plr.133.1663083374514; Tue, 13 Sep 2022 08:36:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1663083374; cv=none; d=google.com; s=arc-20160816; b=m6aeICtbnu7qjOslTD06kzxF9gTBnGEGQDjBk98cAXKMxL9d85RPDBsBqsIT8PMl6w cXaUPRPSajI6Gl3mcXgl+23BcSUwLmQg7UQqMP1k5GNGE5sU59Z462GfRI1LAkUVcEIX jRuL4fFoAIcR697+ea0XhmwObtbz9EZdAwM1FpjdOCBmz9JOyqTFzdycqT6l2bi7odEW CKZTeIzor134h0udCiQr3I2RsvTGrDYmQuVVlaRVdj3uxhyR0e9skw4+rlQVPpmOvyBE j1Wzm5tMS7oKEmtloAwqWfS3z3nLdvMkXEg72H8sGtLoUfj2gDUnqq8qoOjCMhRWGp8X gVlw== 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=lbByizYtVpDq+czHRXtNGUA5c/X6UYGt2NI5A34qkC4=; b=XmnPrf6Xr2iYcmp/u/7pOPPsKIXdrAEK7uWhINo9OHGYLy8I4uwfPIE/I5TuNzYiOG hg3HG+svCvP42WGZtU3i2GICy2+Pf4EOiATzyX6oLO43/qA26wQHDxOnAs//7o8FtEXe +1gHR/IqftQLMWEM1dJAGLf2AAbk68hbBjA4KqwgpGs2QvH92fxptiVmmq8YJIzKE3YE tPuNCwbK21yzEzWvClHQMKDl8i3X6E/WJt3LNucrnh+NhIjjiVnglyDnkT8daiZ9jXtA gJAdwvSNEga4PLV7kKX5iKTFw1NKa77ZVmZYqLzZZrfZuNKUT5iDrNKJbHv2aM2XPmVg 8AeA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=ONgky8Go; 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 f14-20020a056a00238e00b0052dc0e53dcdsi14818266pfc.258.2022.09.13.08.36.02; Tue, 13 Sep 2022 08:36:14 -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=ONgky8Go; 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 S234818AbiIMO7x (ORCPT + 99 others); Tue, 13 Sep 2022 10:59:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34054 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234964AbiIMO5N (ORCPT ); Tue, 13 Sep 2022 10:57:13 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1BA9B62AB2; Tue, 13 Sep 2022 07:28:13 -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 dfw.source.kernel.org (Postfix) with ESMTPS id 293AD614AA; Tue, 13 Sep 2022 14:28:13 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 40445C433C1; Tue, 13 Sep 2022 14:28:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1663079292; bh=lpazVn+TDsYK5GKA9iWWyLBDb2pAAjMWK2hSETqYsOs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ONgky8Gox61f3C0/96gA5vKfHqoi0m4A42ZfDz62Iv5whBMRh6awycS1gK6w+ReVa 5zK4FdZ+MLt2CvOTf8KXMYYmu/Bknm5Z56vtXSHXorIYAIXhRxUPHJs9dIswNUms5G eLsFbjyhVCsyj6aAvxny0Nsf0vtu2sIYjnHZAUtE= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Tasos Sahanidis , Takashi Iwai Subject: [PATCH 5.4 077/108] ALSA: emu10k1: Fix out of bounds access in snd_emu10k1_pcm_channel_alloc() Date: Tue, 13 Sep 2022 16:06:48 +0200 Message-Id: <20220913140356.943689456@linuxfoundation.org> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20220913140353.549108748@linuxfoundation.org> References: <20220913140353.549108748@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 @@ -123,7 +123,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; } }