Received: by 2002:a25:5b86:0:0:0:0:0 with SMTP id p128csp2086312ybb; Fri, 29 Mar 2019 18:43:08 -0700 (PDT) X-Google-Smtp-Source: APXvYqxXOm8XkiHOR8htor92uwVtlXvIVcShBfyd1yee1iBnQ0QvVOySRGlV/h9dxXb+MezAPkoN X-Received: by 2002:a62:cfc4:: with SMTP id b187mr22382743pfg.130.1553910187978; Fri, 29 Mar 2019 18:43:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1553910187; cv=none; d=google.com; s=arc-20160816; b=o4SGs2sCGhi0XbMB4WvYlbzE+SutaeQxms/A4bbeMOEbWWKpTmB1vpUj5p7KKmiVzx aHENuDIMQfW4dpJe+hLfSbFt3r9NBqJibIMePvtPvv96krBVn0M/L/gHbFIFy/reuVVP OJVhwz6XGc2s7PQ7Z2vDSJEWP800rO3RPn/9t6x+NkhoFrIzUAdGrLtIRu3B0F0hHOXH Dr4Aj+jQ0MpukIpk64qcN82/cPNhKqT3wbjszsjQuLCNRJyWaPk+GCUDkz5azq1z97RQ EOR+T/R/TYQrDzHsNcEz7zNrWGhtDut40khoxw5yxzLkcZ+62r++yav9jjYOvDH7aIDr SQQQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=pV/+ZErBRxT1l4YtiYnXKq9sFlsu1uj58eTRp2pbR2U=; b=w5JRRMxSoAcdcftsvGtDYGNpQ5/Jg/wZtL9oFpdgQUk39Y+REkBlgzUxKMZ0UEnZMs iAHAAvful/W+KsNEqKA60hSk+HCEUoqOpkD3vXKIErVz2tLX6NuI9Ey+yF9S5P6MzVfU bs3mrjmweB/gmymTQ4r3Tb1nQWgeLhEYZFd/AyCg90J0zvUC5tHDZIzThPR/fIaDHgeV eY1x6yv5elfHXwds+aIcRbx65EvNBVzZsOFH04KPkVFz7riKs9ZnkYYMtQo98DjLPVwd oXwZVhpn+GcHtagl73UCZj6ccGoEGWzZpwyggCn6N9qcRgDwbIPE1W1tJmXyQfE3s8J2 u08w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=y97U5r8R; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id q20si3175291plr.136.2019.03.29.18.42.52; Fri, 29 Mar 2019 18:43:07 -0700 (PDT) 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; dkim=pass header.i=@kernel.org header.s=default header.b=y97U5r8R; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731453AbfC3BlA (ORCPT + 99 others); Fri, 29 Mar 2019 21:41:00 -0400 Received: from mail.kernel.org ([198.145.29.99]:35838 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730740AbfC3B3D (ORCPT ); Fri, 29 Mar 2019 21:29:03 -0400 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 6346E218FC; Sat, 30 Mar 2019 01:29:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1553909343; bh=grw32U0dqpgwD1a6Hxj9EFSfLAWiwA5F8XAHInIRm8k=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=y97U5r8RWGdefVzkyQMVcanbAC6BMgYN60TF5hjXEOt7QCfHdseLFRKKiBmX1Vd+4 Y0nzvCZcTwXdikiMibFqioaF1ZbLj+bpU4U3vsc6sYgA49EXRgq5NPg5+ADFO+HT41 YK6QYsjDCgFfMbt262JurQwo5SLE9fxF/xSI1isY= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Rohit kumar , Mark Brown , Sasha Levin Subject: [PATCH AUTOSEL 4.19 07/57] ASoC: Fix UBSAN warning at snd_soc_get/put_volsw_sx() Date: Fri, 29 Mar 2019 21:28:00 -0400 Message-Id: <20190330012854.32212-7-sashal@kernel.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20190330012854.32212-1-sashal@kernel.org> References: <20190330012854.32212-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Rohit kumar [ Upstream commit ae7d1247d8673ebfd686b17e759d4be391165368 ] 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 Signed-off-by: Mark Brown Signed-off-by: Sasha Levin --- 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 592efb370c44..f4dc3d445aae 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 = (1U << (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 = (1U << (fls(min + max) - 1)) - 1; int err = 0; unsigned int val, val_mask, val2 = 0; -- 2.19.1