Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp9046053pxu; Mon, 28 Dec 2020 05:19:11 -0800 (PST) X-Google-Smtp-Source: ABdhPJyVvQz2Ulw0EtNVn4mcgPNcC3dwGZqlhbXqYrRrNR7+Xz/ZvW43FWobfG+8JqVAwQTgY/3q X-Received: by 2002:a17:906:8051:: with SMTP id x17mr40087430ejw.430.1609161550845; Mon, 28 Dec 2020 05:19:10 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1609161550; cv=none; d=google.com; s=arc-20160816; b=M5U8DLGErz+YRLNJivXcgDtcf8pvd4ZfQEPIHEae5SAmYW1KuC8L9Clq4WqKyYlgMP GqW9ZEL7LxDYmUBo4MnZr5LDLZLAcbHYaEQY8HMH9HKCZ8bGDa8CoQzgXO4vSiu66w+a lVhpXc+XFwRxcgumhJNFfQoYGvx4XrUXWoGLxY+jRluVFbWh+xJbJ+pbFrZdB6o2Pmp8 WuxvworuNeW6xkfH5Wzrlns9Um5rm5g+iEsCIysIhOE5TsZIr9XhtQZs3knn8IFrsW0C OuKWq/xMSVREjPUH4sx0FyFcRbp5a+hFuh4qMHiOrmj3TYnBru5HTbSHdmK3Mj1slHZs 5mMg== 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=ZcJBgSTgy0e/JEQC4abjkiJF9Qxa84oenoePG2FEAEA=; b=ivPaf3SoZuC4HuGGt5TF1GKKq0VH+ufhnYgEigbg/GYVVuOmDiAlAXy+Qc9M00ND6A 33U3JfhyF0wzf6Z4ZHKt2ZnlWlWwM5Jb72fFC/DUSGnPf0MbSuG7VT4YTyhNYpHyUGcw /djlRneErk+lZVKuBL7V0/F7F7Onk4+3PPiO0Oi7tk9KB6Y2Iv6tZWAmczRALukFLg+d u4gZEQKGljNFl4Zoq3cpPJ7PoKUz2YAKVRrgmECixMUeS8N0Ig2miF9Od/kr9PGsNEUp opPiPibqcEuXDdCJqEHC611Vk//7PC+ugQINW3KuOvxtu2KYXHbsLl3NRfXmgALkg+J2 RNAA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=roo9X2L6; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id t6si20375258edq.353.2020.12.28.05.18.48; Mon, 28 Dec 2020 05:19:10 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=roo9X2L6; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S1733306AbgL1NQt (ORCPT + 99 others); Mon, 28 Dec 2020 08:16:49 -0500 Received: from mail.kernel.org ([198.145.29.99]:45082 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1733276AbgL1NQq (ORCPT ); Mon, 28 Dec 2020 08:16:46 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 8796822582; Mon, 28 Dec 2020 13:16:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1609161365; bh=4pKSHHTAMsA8a3Dqhp1akLyFJ8DIxV3rVTcOKmonuZU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=roo9X2L6+N4mAtxQWUOjm/advjQZ+WXhYiSJXsRLXk5RRBOmXc+qzlmI6e0OYeMBI Gown46/KfV8eQphNbPBiF+d4i6DUGg8xXSMmaNNGEkgY0l6n/y2thV/Ky/1vvGzwBB QUmHtLNVb80qYxtDaMWBW3Y0PDdrHpr1lw0Cwn58= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, syzbot+33ef0b6639a8d2d42b4c@syzkaller.appspotmail.com, Takashi Iwai Subject: [PATCH 4.14 189/242] ALSA: pcm: oss: Fix a few more UBSAN fixes Date: Mon, 28 Dec 2020 13:49:54 +0100 Message-Id: <20201228124913.998531846@linuxfoundation.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201228124904.654293249@linuxfoundation.org> References: <20201228124904.654293249@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Takashi Iwai commit 11cb881bf075cea41092a20236ba708b18e1dbb2 upstream. There are a few places that call round{up|down}_pow_of_two() with the value zero, and this causes undefined behavior warnings. Avoid calling those macros if such a nonsense value is passed; it's a minor optimization as well, as we handle it as either an error or a value to be skipped, instead. Reported-by: syzbot+33ef0b6639a8d2d42b4c@syzkaller.appspotmail.com Cc: Link: https://lore.kernel.org/r/20201218161730.26596-1-tiwai@suse.de Signed-off-by: Takashi Iwai Signed-off-by: Greg Kroah-Hartman --- sound/core/oss/pcm_oss.c | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) --- a/sound/core/oss/pcm_oss.c +++ b/sound/core/oss/pcm_oss.c @@ -708,6 +708,8 @@ static int snd_pcm_oss_period_size(struc oss_buffer_size = snd_pcm_plug_client_size(substream, snd_pcm_hw_param_value_max(slave_params, SNDRV_PCM_HW_PARAM_BUFFER_SIZE, NULL)) * oss_frame_size; + if (!oss_buffer_size) + return -EINVAL; oss_buffer_size = rounddown_pow_of_two(oss_buffer_size); if (atomic_read(&substream->mmap_count)) { if (oss_buffer_size > runtime->oss.mmap_bytes) @@ -743,17 +745,21 @@ static int snd_pcm_oss_period_size(struc min_period_size = snd_pcm_plug_client_size(substream, snd_pcm_hw_param_value_min(slave_params, SNDRV_PCM_HW_PARAM_PERIOD_SIZE, NULL)); - min_period_size *= oss_frame_size; - min_period_size = roundup_pow_of_two(min_period_size); - if (oss_period_size < min_period_size) - oss_period_size = min_period_size; + if (min_period_size) { + min_period_size *= oss_frame_size; + min_period_size = roundup_pow_of_two(min_period_size); + if (oss_period_size < min_period_size) + oss_period_size = min_period_size; + } max_period_size = snd_pcm_plug_client_size(substream, snd_pcm_hw_param_value_max(slave_params, SNDRV_PCM_HW_PARAM_PERIOD_SIZE, NULL)); - max_period_size *= oss_frame_size; - max_period_size = rounddown_pow_of_two(max_period_size); - if (oss_period_size > max_period_size) - oss_period_size = max_period_size; + if (max_period_size) { + max_period_size *= oss_frame_size; + max_period_size = rounddown_pow_of_two(max_period_size); + if (oss_period_size > max_period_size) + oss_period_size = max_period_size; + } oss_periods = oss_buffer_size / oss_period_size;