Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3321774imu; Sun, 11 Nov 2018 12:19:53 -0800 (PST) X-Google-Smtp-Source: AJdET5fOhZLDleZ8ijYX9laWPMxC7nh9pR+SGe3IAPOlOvgGOK8HFqoMc83R2IZlP9z+KRWi5BMU X-Received: by 2002:a17:902:8210:: with SMTP id x16-v6mr17481568pln.129.1541967593694; Sun, 11 Nov 2018 12:19:53 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541967593; cv=none; d=google.com; s=arc-20160816; b=FwpRjYZijSHtSjCwb75XVT/QKaHQ6iL303z60+1JRP/EF0Amv56PUwvGYEbUSrTAk4 90eoGtA2zJrT3ZmsgKSYr12mQQ5XqhUsMOc5o/NoQe05LUtKEsmvV+TFN2wd8MaN7hXZ M5rOm5+MMpwirSmZUE4YJmFSxV/1FY5A691L0DoO73H1gQb13e1q2SsqwgnmLoy+5miF /AdRg7sTgyfDUMqz1DKNFUXZvSEA0EXwKjjalsfEP6KcUJ/19PucJs3++Le3XPj6um6p A/oy0LeW313XfU3atjPOGFjdA3k5pWxdNZG+ulVc2Jp10gkAsXv22EW6kiBQfzKmBr4+ ZYZw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:subject:message-id:date:cc:to :from:mime-version:content-transfer-encoding:content-disposition; bh=5uNXuyGgIfTLIsj3kPoFHijuNG9jP2gw2T1cjN2youA=; b=KFWGkjaPvxBso0x0HJZqBmQJmCOvrsPrJIW6lDxkDIzEoisTsgeDRHUGGNsIQBTML6 pIqvmUw0Cr6y8lOF88PFRq5MH98JqTUlf6z/oTNsEgO7/oNBbsQJSPDTZvltAbHq0mtc sIbIiDoYg2kh4qObxMZMYyJxf8cJ2JmlBFRAFDxfxdb8d14VpPDSEtAfa7OYAyjre1La ++t2JamsH0sKF1OvHpfZ3rzGDnLv0ahREEdDHu5UkQINQ37x5/fEkhOKb4f8G6SHc8Wp ZPxcU/EoR1pyg6r/B57Tb4RtlvFbYunWMmMOa7uu2qHnzfIrF+H5dOpR3LdqnDzem8S0 A2mA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b131si14257524pga.51.2018.11.11.12.19.38; Sun, 11 Nov 2018 12:19:53 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731639AbeKLGEQ (ORCPT + 99 others); Mon, 12 Nov 2018 01:04:16 -0500 Received: from shadbolt.e.decadent.org.uk ([88.96.1.126]:52898 "EHLO shadbolt.e.decadent.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726816AbeKLGEQ (ORCPT ); Mon, 12 Nov 2018 01:04:16 -0500 Received: from [192.168.4.242] (helo=deadeye) by shadbolt.decadent.org.uk with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1gLvsy-0000oO-72; Sun, 11 Nov 2018 19:59:08 +0000 Received: from ben by deadeye with local (Exim 4.91) (envelope-from ) id 1gLvsU-0001d9-5K; Sun, 11 Nov 2018 19:58:38 +0000 Content-Type: text/plain; charset="UTF-8" Content-Disposition: inline Content-Transfer-Encoding: 8bit MIME-Version: 1.0 From: Ben Hutchings To: linux-kernel@vger.kernel.org, stable@vger.kernel.org CC: akpm@linux-foundation.org, "Takashi Iwai" Date: Sun, 11 Nov 2018 19:49:05 +0000 Message-ID: X-Mailer: LinuxStableQueue (scripts by bwh) Subject: [PATCH 3.16 193/366] ALSA: timer: Fix UBSAN warning at SNDRV_TIMER_IOCTL_NEXT_DEVICE ioctl In-Reply-To: X-SA-Exim-Connect-IP: 192.168.4.242 X-SA-Exim-Mail-From: ben@decadent.org.uk X-SA-Exim-Scanned: No (on shadbolt.decadent.org.uk); SAEximRunCond expanded to false Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 3.16.61-rc1 review patch. If anyone has any objections, please let me know. ------------------ From: Takashi Iwai commit b41f794f284966fd6ec634111e3b40d241389f96 upstream. The kernel may spew a WARNING about UBSAN undefined behavior at handling ALSA timer ioctl SNDRV_TIMER_IOCTL_NEXT_DEVICE: UBSAN: Undefined behaviour in sound/core/timer.c:1524:19 signed integer overflow: 2147483647 + 1 cannot be represented in type 'int' Call Trace: __dump_stack lib/dump_stack.c:77 [inline] dump_stack+0x122/0x1c8 lib/dump_stack.c:113 ubsan_epilogue+0x12/0x86 lib/ubsan.c:159 handle_overflow+0x1c2/0x21f lib/ubsan.c:190 __ubsan_handle_add_overflow+0x2a/0x31 lib/ubsan.c:198 snd_timer_user_next_device sound/core/timer.c:1524 [inline] __snd_timer_user_ioctl+0x204d/0x2520 sound/core/timer.c:1939 snd_timer_user_ioctl+0x67/0x95 sound/core/timer.c:1994 .... It happens only when a value with INT_MAX is passed, as we're incrementing it unconditionally. So the fix is trivial, check the value with INT_MAX. Although the bug itself is fairly harmless, it's better to fix it so that fuzzers won't hit this again later. Bugzilla: https://bugzilla.kernel.org/show_bug.cgi?id=200213 Reported-and-tested-by: Team OWL337 Signed-off-by: Takashi Iwai [bwh: Backported to 3.16: adjust context, indentation] Signed-off-by: Ben Hutchings --- sound/core/timer.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) --- a/sound/core/timer.c +++ b/sound/core/timer.c @@ -1476,7 +1476,7 @@ static int snd_timer_user_next_device(st } else { if (id.subdevice < 0) { id.subdevice = 0; - } else { + } else if (id.subdevice < INT_MAX) { id.subdevice++; } }