Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp9038501pxu; Mon, 28 Dec 2020 05:07:44 -0800 (PST) X-Google-Smtp-Source: ABdhPJxjFePDE162dTKmpOAks0ymoBweRKtzhiBs+fjcRWCUP0tdrphZf4fRGA54oNneUpSNTz6M X-Received: by 2002:a17:906:b7d6:: with SMTP id fy22mr38027544ejb.219.1609160864597; Mon, 28 Dec 2020 05:07:44 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1609160864; cv=none; d=google.com; s=arc-20160816; b=K0ioUHz+JmY3Gpuj8ndg6xvbfykt29bVAFeygWf2Pt8JSLmc4yEUo3OWxRN8Yp3KEr EfXgS9JeDHx1ISb+oKsLtnsp+5QIWvcA+AyrdEgij5bMcFJoCls4cpiavx3d7ZiTz0gS MPqQvQKV4kZ4IcxrgdLM9y+uh8yxF+a0mDlStTlVNAxMK4G7Gal0Q9JCzY6x9a2liaQW T65fQH7DMfIRkXgsVqDgk2aEELW0R5I2ejY6Hy6W2npRe6SyOpw+rlHMqN+wMIEKtu0w TkB3ntgQo0ap9cGf55xhazogRwo3gUFvrYuyylydrVn2LzrSEedRkB7DVK+8kKuzZy1J 8+0w== 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=al0fIY40kCBVdDx1sk/dwTj9uLOizeSHhboLbgR+ALY=; b=nJDTvMzJlyVHSRAd0JF8Ffba8Clb8vd+3+271xEEj5nCB+dh8SIvyGX3zXFFwnsuZU JkOG5Gsn3cXM/nHI6/TPF+AMR718WQLr+qnVrYMPopvUvYI89zb5cC7cy+EIk2Vs+WDG kya6UIadp8lMftcHG61U+p+HHmGGsp9jjEz+Clp5xlc2RQe+CVUaXEt3lzgczjJz7tNE py2DsbkXsk+R2ump1RFx89TmwIx/aVWmAADpbTLyHUBK1fyIuSa8aMIlSDnlvTsrJJx6 0OTbXdkeJI+QH+PDj26QObXINsxY1LhnEeU3+nhWrGWIswbypd0AMuxDAb2yezHUk0XZ uV/w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=xdn03ESY; 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 lw27si18604680ejb.35.2020.12.28.05.07.20; Mon, 28 Dec 2020 05:07:44 -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=xdn03ESY; 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 S1730618AbgL1NF1 (ORCPT + 99 others); Mon, 28 Dec 2020 08:05:27 -0500 Received: from mail.kernel.org ([198.145.29.99]:60522 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730548AbgL1NFD (ORCPT ); Mon, 28 Dec 2020 08:05:03 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 3455D207C9; Mon, 28 Dec 2020 13:04:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1609160687; bh=WdurbeE7w9m4BV2zK+5mwDEtJ8g1Z6Fx4p6Gs1JHmNA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=xdn03ESYc6nC7iEYRGuk8hYSBV7zNtIqOzAEfWjyQ6m+IfMs4tu3ZK2+NcIHD1dZm 77Di0Za+tGd1dg8cCiIRpypyxjFh2xiBoHpXUUgJKG2nyxVi47420ZJbtVBK8PRi8c 3YL1/Xbbl9ybHLBXHzk83wT3tsBbHMMG4odVvgQo= 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.9 137/175] ALSA: pcm: oss: Fix a few more UBSAN fixes Date: Mon, 28 Dec 2020 13:49:50 +0100 Message-Id: <20201228124859.887924291@linuxfoundation.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201228124853.216621466@linuxfoundation.org> References: <20201228124853.216621466@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 @@ -719,6 +719,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) @@ -754,17 +756,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;