Message ID | 20240118073619.40538-1-arefev@swemel.ru |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel+bounces-29768-ouuuleilei=gmail.com@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:2bc4:b0:101:a8e8:374 with SMTP id hx4csp180364dyb; Wed, 17 Jan 2024 23:36:46 -0800 (PST) X-Google-Smtp-Source: AGHT+IEU1AVbuBWmRfK+EzZ7oEfecArxuAtoNg8/TZ35d2ZwgYPUt73UinnPB11Sm8ornP9nWJ0Z X-Received: by 2002:a17:906:2ac7:b0:a29:d805:20ec with SMTP id m7-20020a1709062ac700b00a29d80520ecmr2105635eje.22.1705563406183; Wed, 17 Jan 2024 23:36:46 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1705563406; cv=pass; d=google.com; s=arc-20160816; b=KOYGNUkqxgM1dRzuK62nDdwJSh+oQjcf4NP0rWl8MD8OumVCqG9/eALTEViOuFHNXe JMkugnNVfzDzutvXkO3hL9uv0KQX08uoswEckeOTrxqF9NgIxyDDOJMPBx4jmpHddJ00 7neO95l2T9PGrZOyJsYv3nIdibWI3L/1cO6pKPOdsNRn0MTwhPhUxgMSikUbYQeboj/6 aqubdA9f25eDV0MV5bwZhaNJIylXhKDx4CjA9DCosb+B53nONFZeF/iAte8D1IkJHsfp F42/GiQyOMjlttJpLtiaGTz98bcm8Lbu1IPzkC72oE+tq9sz75shf2SOjnukIiQeEwyc HDVQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :dkim-signature:from; bh=w6I24PSFroCRy+qrdhWCnhtKFkiJu5pLtQY++vEovX4=; fh=J17N+tWcsUyyHxFwTXdyJ0OLDG1mMjQQJxwgF0L4QIo=; b=FMYc/ytZUIyG3py+EMWbRRdsiPqUVAibvP+dB75dSnIIa1DF4G1J+/+QRxHnJytApU 1HkSJ5GJq7XW/XaxIduUQowyHFdIqbxviu3+dOHTiUHU3Xc1jnede8ZsyTxLhQYbg0/0 tK+gIScOAb53fLTJJn5Tj79bw0vhOK3+n5OU2h3p10hoFpu+811S+Jq3yw5HksSRpVGi 2HT/Yda3HkZKVC1YnpVmxLTlvqrgUtITWEE9iKhbiXuADUmpk0i3dVENs72MZpY3jCf8 YAmqw9KsEex1YT0vKhdk/ZHrg3gc1f02TXsEIHV2fseUudY+Q6kmavivA5G2+lr7XFdX Iw/w== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@swemel.ru header.s=mail header.b=AvT6pznM; arc=pass (i=1 spf=pass spfdomain=swemel.ru dkim=pass dkdomain=swemel.ru dmarc=pass fromdomain=swemel.ru); spf=pass (google.com: domain of linux-kernel+bounces-29768-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-29768-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=swemel.ru Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id i1-20020a170906444100b00a2f0d69b2b8si557862ejp.641.2024.01.17.23.36.46 for <ouuuleilei@gmail.com> (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Jan 2024 23:36:46 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-29768-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@swemel.ru header.s=mail header.b=AvT6pznM; arc=pass (i=1 spf=pass spfdomain=swemel.ru dkim=pass dkdomain=swemel.ru dmarc=pass fromdomain=swemel.ru); spf=pass (google.com: domain of linux-kernel+bounces-29768-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-29768-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=swemel.ru Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id C98E91F21A8B for <ouuuleilei@gmail.com>; Thu, 18 Jan 2024 07:36:45 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 0ED7AC126; Thu, 18 Jan 2024 07:36:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=swemel.ru header.i=@swemel.ru header.b="AvT6pznM" Received: from mx.swemel.ru (mx.swemel.ru [95.143.211.150]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A4394B645 for <linux-kernel@vger.kernel.org>; Thu, 18 Jan 2024 07:36:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.143.211.150 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705563388; cv=none; b=lvwZ1jJscahz6DIS1sStBljn8ZUm+Q1aewOwIXxHA3HlKVyAiDMmKJjqPuE87O5c/vzKABnDt2bSMWBm1nysfOO3/oILCwAS3eJ3f12ukmCIArvNlec3xXicGPBCHZFNb8dKZJyjIiQ2Ns5OtrAXP8O3mXrsEimlQbYrpRVT76w= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705563388; c=relaxed/simple; bh=3p0yab2HKEbLIghYqIUST037bwwznw2PGfCNieqmbb4=; h=From:DKIM-Signature:To:Cc:Subject:Date:Message-Id:MIME-Version: Content-Transfer-Encoding; b=KD4Agf6We1qqwKC2pdM0LnVCV43z7OHZApWWEsUubj68LkUZgFR07kh2kMYqdc8vwr5qi5Zrf3ng+2Q3BsfNnFU+XH7dVARtX2vmAR2FBxWLMGAjRxZ1EnatgzbAegTh2EkTKHk5o2x7eKNSBGanVNUqds0tI49sF6Q1KfsXCnA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=swemel.ru; spf=pass smtp.mailfrom=swemel.ru; dkim=pass (1024-bit key) header.d=swemel.ru header.i=@swemel.ru header.b=AvT6pznM; arc=none smtp.client-ip=95.143.211.150 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=swemel.ru Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=swemel.ru From: Denis Arefev <arefev@swemel.ru> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=swemel.ru; s=mail; t=1705563379; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=w6I24PSFroCRy+qrdhWCnhtKFkiJu5pLtQY++vEovX4=; b=AvT6pznMxXNFtWEwYo0uwZOGZnNfvNbKdg6RhlvjiCEOgR7fqcuJiu1L1FNt3br+ImU7rS G0SynVdDXXNtm6y/bvQC3uZmPiVAoPTt20IUPgAoDSCC/FpGaeGiANqcIvdPB7lpPhF4NE aZA42X8Lpx7D0xH0fwFNpr0GERBkckQ= To: Ian Abbott <abbotti@mev.co.uk> Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>, H Hartley Sweeten <hsweeten@visionengravers.com>, linux-kernel@vger.kernel.org (open list), lvc-project@linuxtesting.org Subject: [PATCH] comedi: drivers: ni_tio: Fix arithmetic expression overflow Date: Thu, 18 Jan 2024 10:36:19 +0300 Message-Id: <20240118073619.40538-1-arefev@swemel.ru> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: <linux-kernel.vger.kernel.org> List-Subscribe: <mailto:linux-kernel+subscribe@vger.kernel.org> List-Unsubscribe: <mailto:linux-kernel+unsubscribe@vger.kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1788412854162956996 X-GMAIL-MSGID: 1788412854162956996 |
Series |
comedi: drivers: ni_tio: Fix arithmetic expression overflow
|
|
Commit Message
Denis Arefev
Jan. 18, 2024, 7:36 a.m. UTC
The value of an arithmetic expression period_ns * 1000 is subject to overflow due to a failure to cast operands to a larger data type before performing arithmetic Found by Linux Verification Center (linuxtesting.org) with SVACE. Reviewed-by: Ian Abbott <abbotti@mev.co.uk> Signed-off-by: Denis Arefev <arefev@swemel.ru> --- drivers/comedi/drivers/ni_tio.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
Comments
On Thu, Jan 18, 2024 at 10:36:19AM +0300, Denis Arefev wrote: > The value of an arithmetic expression period_ns * 1000 is subject > to overflow due to a failure to cast operands to a larger data > type before performing arithmetic > > Found by Linux Verification Center (linuxtesting.org) with SVACE. > > Reviewed-by: Ian Abbott <abbotti@mev.co.uk> > Signed-off-by: Denis Arefev <arefev@swemel.ru> > --- > drivers/comedi/drivers/ni_tio.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/drivers/comedi/drivers/ni_tio.c b/drivers/comedi/drivers/ni_tio.c > index da6826d77e60..acc914903c70 100644 > --- a/drivers/comedi/drivers/ni_tio.c > +++ b/drivers/comedi/drivers/ni_tio.c > @@ -800,7 +800,7 @@ static int ni_tio_set_clock_src(struct ni_gpct *counter, > GI_PRESCALE_X2(counter_dev->variant) | > GI_PRESCALE_X8(counter_dev->variant), bits); > } > - counter->clock_period_ps = period_ns * 1000; > + counter->clock_period_ps = period_ns * 1000UL; Can period_ns ever be "too big" to cause such an overflow? And what commit id does this fix? thanks, greg k-h
On 18/01/2024 09:32, Greg Kroah-Hartman wrote: > On Thu, Jan 18, 2024 at 10:36:19AM +0300, Denis Arefev wrote: >> The value of an arithmetic expression period_ns * 1000 is subject >> to overflow due to a failure to cast operands to a larger data >> type before performing arithmetic >> >> Found by Linux Verification Center (linuxtesting.org) with SVACE. >> >> Reviewed-by: Ian Abbott <abbotti@mev.co.uk> >> Signed-off-by: Denis Arefev <arefev@swemel.ru> >> --- >> drivers/comedi/drivers/ni_tio.c | 2 +- >> 1 file changed, 1 insertion(+), 1 deletion(-) >> >> diff --git a/drivers/comedi/drivers/ni_tio.c b/drivers/comedi/drivers/ni_tio.c >> index da6826d77e60..acc914903c70 100644 >> --- a/drivers/comedi/drivers/ni_tio.c >> +++ b/drivers/comedi/drivers/ni_tio.c >> @@ -800,7 +800,7 @@ static int ni_tio_set_clock_src(struct ni_gpct *counter, >> GI_PRESCALE_X2(counter_dev->variant) | >> GI_PRESCALE_X8(counter_dev->variant), bits); >> } >> - counter->clock_period_ps = period_ns * 1000; >> + counter->clock_period_ps = period_ns * 1000UL; > > Can period_ns ever be "too big" to cause such an overflow? The period_ns value comes from user-space and could be any unsigned int value. It's used to let the driver know the period of an external clock source. > And what commit id does this fix? Fixes: 3e90b1c7ebe9 ("staging: comedi: ni_tio: tidy up ni_tio_set_clock_src() and helpers") Cc: <stable@vger.kernel.org> # v5.15+ The first affected kernel version is v3.17. This patch should apply cleanly to v5.13 onwards (when comedi was moved out of drivers/staging), but earlier stable/longterm kernels would require a backported patch. @Denis, if you could add the above Fixes: and Cc: lines to a v2 patch, that would be great! > > thanks, > > greg k-h
diff --git a/drivers/comedi/drivers/ni_tio.c b/drivers/comedi/drivers/ni_tio.c index da6826d77e60..acc914903c70 100644 --- a/drivers/comedi/drivers/ni_tio.c +++ b/drivers/comedi/drivers/ni_tio.c @@ -800,7 +800,7 @@ static int ni_tio_set_clock_src(struct ni_gpct *counter, GI_PRESCALE_X2(counter_dev->variant) | GI_PRESCALE_X8(counter_dev->variant), bits); } - counter->clock_period_ps = period_ns * 1000; + counter->clock_period_ps = period_ns * 1000UL; ni_tio_set_sync_mode(counter); return 0; }