From patchwork Mon Sep 10 17:33:56 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rohit Kumar X-Patchwork-Id: 10594667 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 4C72813B8 for ; Mon, 10 Sep 2018 17:54:04 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3B1A92924A for ; Mon, 10 Sep 2018 17:54:04 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2F3BC293A0; Mon, 10 Sep 2018 17:54:04 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 80CF42924A for ; Mon, 10 Sep 2018 17:54:03 +0000 (UTC) Received: from alsa0.perex.cz (localhost [127.0.0.1]) by alsa0.perex.cz (Postfix) with ESMTP id 518F926787B; Mon, 10 Sep 2018 19:54:02 +0200 (CEST) X-Original-To: alsa-devel@alsa-project.org Delivered-To: alsa-devel@alsa-project.org Received: by alsa0.perex.cz (Postfix, from userid 1000) id 9014626789B; Mon, 10 Sep 2018 19:54:00 +0200 (CEST) Received: from smtp.codeaurora.org (smtp.codeaurora.org [198.145.29.96]) by alsa0.perex.cz (Postfix) with ESMTP id 11D9C267891 for ; Mon, 10 Sep 2018 19:53:56 +0200 (CEST) Received: by smtp.codeaurora.org (Postfix, from userid 1000) id 86AE860594; Mon, 10 Sep 2018 17:34:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1536600853; bh=EvYbUi8Q+LDt1ZZ5JBi/TKvwmMbFIhypoPuZJgSU2Cs=; h=From:To:Cc:Subject:Date:From; b=XTXrK1gEqxKQIAt93AanmQ/sqk1Q6cVyooDl93pW3jUZ4W4GGg80mhNW8LXKqz4TO ACTiWoge/jf9RF8gXAw78l8L0znf8GWRVq8nArohRkphsdFTHvRsG9BOZMnCoS1Kju DKK382cZ08sd7HV4EfLyRjre3ys0IfQg5RGJ0PsU= Received: from rohkumar-linux.qualcomm.com (blr-c-bdr-fw-01_globalnat_allzones-outside.qualcomm.com [103.229.19.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: rohitkr@codeaurora.org) by smtp.codeaurora.org (Postfix) with ESMTPSA id 28F4960558; Mon, 10 Sep 2018 17:34:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1536600853; bh=EvYbUi8Q+LDt1ZZ5JBi/TKvwmMbFIhypoPuZJgSU2Cs=; h=From:To:Cc:Subject:Date:From; b=XTXrK1gEqxKQIAt93AanmQ/sqk1Q6cVyooDl93pW3jUZ4W4GGg80mhNW8LXKqz4TO ACTiWoge/jf9RF8gXAw78l8L0znf8GWRVq8nArohRkphsdFTHvRsG9BOZMnCoS1Kju DKK382cZ08sd7HV4EfLyRjre3ys0IfQg5RGJ0PsU= DMARC-Filter: OpenDMARC Filter v1.3.2 smtp.codeaurora.org 28F4960558 Authentication-Results: pdx-caf-mail.web.codeaurora.org; dmarc=none (p=none dis=none) header.from=codeaurora.org Authentication-Results: pdx-caf-mail.web.codeaurora.org; spf=none smtp.mailfrom=rohitkr@codeaurora.org From: Rohit kumar To: lgirdwood@gmail.com, broonie@kernel.org, perex@perex.cz, tiwai@suse.com, alsa-devel@alsa-project.org, linux-kernel@vger.kernel.org, rohkumar@qti.qualcomm.com Date: Mon, 10 Sep 2018 23:03:56 +0530 Message-Id: <1536600836-12153-1-git-send-email-rohitkr@codeaurora.org> X-Mailer: git-send-email 1.9.1 Cc: Rohit kumar Subject: [alsa-devel] [PATCH] ASoC: Fix UBSAN warning at snd_soc_get/put_volsw_sx() X-BeenThere: alsa-devel@alsa-project.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Alsa-devel mailing list for ALSA developers - http://www.alsa-project.org" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: alsa-devel-bounces@alsa-project.org Sender: alsa-devel-bounces@alsa-project.org X-Virus-Scanned: ClamAV using ClamSMTP In functions snd_soc_get_volsw_sx() or snd_soc_put_volsw_sx(), if the result of (min + max) is negative, then fls() returns signed integer with value as 32. This leads to signed integer overflow as complete operation is considered as signed integer. UBSAN: Undefined behaviour in sound/soc/soc-ops.c:382:50 signed integer overflow: -2147483648 - 1 cannot be represented in type 'int' Call trace: [] __dump_stack lib/dump_stack.c:15 [inline] [] dump_stack+0xec/0x158 lib/dump_stack.c:51 [] ubsan_epilogue+0x18/0x50 lib/ubsan.c:164 [] handle_overflow+0xf8/0x130 lib/ubsan.c:195 [] __ubsan_handle_sub_overflow+0x34/0x44 lib/ubsan.c:211 [] snd_soc_get_volsw_sx+0x1a8/0x1f8 sound/soc/soc-ops.c:382 Typecast the operation to unsigned int to fix the issue. Signed-off-by: Rohit kumar --- sound/soc/soc-ops.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sound/soc/soc-ops.c b/sound/soc/soc-ops.c index 592efb3..f8e3190 100644 --- a/sound/soc/soc-ops.c +++ b/sound/soc/soc-ops.c @@ -373,7 +373,7 @@ int snd_soc_get_volsw_sx(struct snd_kcontrol *kcontrol, unsigned int rshift = mc->rshift; int max = mc->max; int min = mc->min; - unsigned int mask = (1 << (fls(min + max) - 1)) - 1; + unsigned int mask = ((unsigned int)(1 << (fls(min + max) - 1)) - 1); unsigned int val; int ret; @@ -418,7 +418,7 @@ int snd_soc_put_volsw_sx(struct snd_kcontrol *kcontrol, unsigned int rshift = mc->rshift; int max = mc->max; int min = mc->min; - unsigned int mask = (1 << (fls(min + max) - 1)) - 1; + unsigned int mask = ((unsigned int)(1 << (fls(min + max) - 1)) - 1); int err = 0; unsigned int val, val_mask, val2 = 0;