Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp1874806pxb; Thu, 4 Nov 2021 09:56:59 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyUAMmNLrzmSW1EqKpcVVxDCX2qqTO3K9Vly3/khqkvlJYmeS7935MCMMFL+ycE88po69KK X-Received: by 2002:a6b:d20f:: with SMTP id q15mr19298456iob.39.1636045019154; Thu, 04 Nov 2021 09:56:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1636045019; cv=none; d=google.com; s=arc-20160816; b=ckeLNi7jTL29ovk7BQVVAdm1s3Z5SdbP24ZZr8G9I/KwktzGmXKRz+LoHsxGMBqdYw nCB8ooIIt8KBotWAUV+040u/ZUjwKw9rGDmT3fA3LZvLqWz857FmXfbdUNH7iNo1dkiA YyNua/NNmd4RNb9mL01ms16pfG7wmWSL54+fH9+sF27NRo9hXSU/jMwNErXwuAXyEhNs jpmVOtSLXedBR7oQZNeDjNPRObCrJhFZpg/hJ9dNNqpRDX74SlMFSmTr3UzWBjtxil1a ZbXRCgkoIv0vhUUdiv3sNIewGdPNo4JaKOLCY+GNh+YVb33fVthoPnAL08GPuw50JzXY TIuw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=y5i/ZduOW81D4EUn+I3tHviCo4oaWhUuA+1PrfJRYmc=; b=QuVVXZKQQ+dYZBCvetmo6CVWbRU/LUQOTxMzTgaRPK7zSiFLvt271M0YTlHNh/0y7W 3oGyvj7GmKTRQ8WT2LWBrO63t0yhsUIXoPk+FKsY6Hd+CN5go+LHbzJvnjEwtXuNC4Iu JuNIy+KnmYOL8ZcvGkizLix4i6WUP0Fae+TQavTRLMG4h9O5PGWX/prjI2ykyRMEb3b+ eNMT1dkOjVimbjnFFDYSO7vUAzS2EotgYwinYz1xCbjl8byedmQR3Fpj0/yRxJwpTrLm ggfcYd6VXRaYEs8Xgu0xoXH92KtrWWcTIBA7cnJxikWhlsAt//89y9Dkx10b1jcBIS5I /EFQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@cmpxchg-org.20210112.gappssmtp.com header.s=20210112 header.b=xHGRpmD5; 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=fail (p=NONE sp=NONE dis=NONE) header.from=cmpxchg.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id z16si7411138iln.77.2021.11.04.09.56.46; Thu, 04 Nov 2021 09:56:59 -0700 (PDT) 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=@cmpxchg-org.20210112.gappssmtp.com header.s=20210112 header.b=xHGRpmD5; 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=fail (p=NONE sp=NONE dis=NONE) header.from=cmpxchg.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231881AbhKDQ55 (ORCPT + 99 others); Thu, 4 Nov 2021 12:57:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48930 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231898AbhKDQ54 (ORCPT ); Thu, 4 Nov 2021 12:57:56 -0400 Received: from mail-qv1-xf2e.google.com (mail-qv1-xf2e.google.com [IPv6:2607:f8b0:4864:20::f2e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3962AC061714 for ; Thu, 4 Nov 2021 09:55:18 -0700 (PDT) Received: by mail-qv1-xf2e.google.com with SMTP id b17so5671376qvl.9 for ; Thu, 04 Nov 2021 09:55:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cmpxchg-org.20210112.gappssmtp.com; s=20210112; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=y5i/ZduOW81D4EUn+I3tHviCo4oaWhUuA+1PrfJRYmc=; b=xHGRpmD5UBUQv1iB6YmuOVQPXdj51+ocNGLEACFiywODZIxuxYeGv1nnpgZRYLwWoL Dfau4z36UlxAYjcAYGsh6gvTP3KFzvftPLYJ5N4JYon/TJQP2yAHIdpRrP6pPllZ7W9Z rNDOeKwEVlC62PV162yQonxwx4MvXFLC4MvMR72UndPPB7Zbc+JY7Cn2J2G5yh/aW5t1 Qq3PWjwJhnPtsHq9yqwEVtqrCIW0EGurS+qm40HAk/YBsWPGP3iba7U0tf2JIpPYOWlT Sz5ssJxqER7wwfegEToZrxOVDmc2GcD+GMm6CUeCRqDFb5PKm5yeux7fgRoCPckG/5/V rb8A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=y5i/ZduOW81D4EUn+I3tHviCo4oaWhUuA+1PrfJRYmc=; b=anx+rZGJ05RQafDgV2ketD2SfdupbX5bmUBX7MDKeVJRps2o/vvFUbYHFEdVdVAsUt TV7bMWjBud4QH5FgUb16VxogKIWCaa8mdcPF9+Vx/uoMIAOVt9Ia8Gc45zDoUmpPAp1X 5Tmx/CFPa8XjVl6b2dvyIyizEc+2ktENnZsmfcNdtiiM+3u23KRPF5zpTTFu772QFiXO opltUaP6lq+Kjn/E7Mr+9ry+MRoG8naCf1vyHwoMuHp493KWKn5pdNSwQcO/eSEOm90r t8YeAZlBDygL34nVXHAMKNPaQGtuR2QCvfzpWEKlP7P0kfZYZzuizZvHQm9KYGrHzd3C W8lw== X-Gm-Message-State: AOAM5308BnfEbH1GXn+BGLN3TwnDuC1/Wxmv1xIut0XirxWgRJPrHA5I pY4zLNyl7x0fqUm6Jqubg6AEew== X-Received: by 2002:a05:6214:4019:: with SMTP id kd25mr13847312qvb.27.1636044917471; Thu, 04 Nov 2021 09:55:17 -0700 (PDT) Received: from localhost (cpe-98-15-154-102.hvc.res.rr.com. [98.15.154.102]) by smtp.gmail.com with ESMTPSA id s22sm4167463qko.88.2021.11.04.09.55.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Nov 2021 09:55:16 -0700 (PDT) Date: Thu, 4 Nov 2021 12:55:16 -0400 From: Johannes Weiner To: Ravi Singh Cc: mingo@redhat.com, peterz@infradead.org, linux-kernel@vger.kernel.org, a.sahrawat@samsung.com, v.narang@samsung.com, vishal.goel@samsung.com, Suren Baghdasaryan Subject: Re: [PATCH] psi: fix integer overflow on unsigned int multiply on 32 bit systems Message-ID: References: <1631523095-8672-1-git-send-email-ravi.singh1@samsung.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1631523095-8672-1-git-send-email-ravi.singh1@samsung.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org CC Suren Sorry, this fell through the cracks. On Mon, Sep 13, 2021 at 02:21:35PM +0530, Ravi Singh wrote: > psi accepts window sizes upto WINDOW_MAX_US(10000000). In the case > where window_us is larger than 4294967, the result of an > multiplication overflows an unsigned int/long(4 bytes on 32 bit > system). > > For example, this can happen when the window_us is 5000000 so 5000000 > * 1000 (NSEC_PER_USEC) will result in 5000000000 which is greater than > UINT_MAX(4294967295). Due to this overflow, 705032704 is stored in > t->win.size instead of 5000000000. Now psi will be monitoring the > window size of 705 msecs instead of 5 secs as expected by user. > > Fix this by type casting the first term of the mutiply to a u64. > > Issue doesnot occur on 64 bit systems because NSEC_PER_USEC is of type > long which is 8 bytes on 64 bit systems. > > Signed-off-by: Ravi Singh Fixes: 0e94682b73bf psi: introduce psi monitor Acked-by: Johannes Weiner Peter would you mind taking this through -tip? > --- > kernel/sched/psi.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/kernel/sched/psi.c b/kernel/sched/psi.c > index 1652f2bb5..a2cc33dc2 100644 > --- a/kernel/sched/psi.c > +++ b/kernel/sched/psi.c > @@ -1145,7 +1145,7 @@ struct psi_trigger *psi_trigger_create(struct psi_group *group, > t->group = group; > t->state = state; > t->threshold = threshold_us * NSEC_PER_USEC; > - t->win.size = window_us * NSEC_PER_USEC; > + t->win.size = (u64)window_us * NSEC_PER_USEC; > window_reset(&t->win, 0, 0, 0); > > t->event = 0; > -- > 2.17.1