Received: by 2002:a05:6a10:eb17:0:0:0:0 with SMTP id hx23csp2788437pxb; Mon, 6 Sep 2021 05:30:21 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwQOhgAakLr5Qy3qRniOeoQ8LLjz+tUPJynsOzpU8LMmwn/m8vm+GuykhAr3MmYGK1UsfF9 X-Received: by 2002:a05:6402:1d2d:: with SMTP id dh13mr13307789edb.281.1630931421237; Mon, 06 Sep 2021 05:30:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1630931421; cv=none; d=google.com; s=arc-20160816; b=IbmsD7KrDtGn8ox7R6S2bXV31GRqw/1WcaUwua5hpqOF1mICDdfQq4PRpa8qgJn+ca nUe0+FgiYNl8PmblVeTHo96miarYA738eNM0fIYdsuw5OpYBq6wMNwPB8vhg5AQT2nkw VAHtA8uN+bqpR54/8e8HDC64uobSYKewyA5OzPe99itTf1iqZ23x5i5K8vK/UiwJYaDL oUQ9HtwCTUXbejwa68TQBi+Ip0FyF6+C8Trrt2eSc2iZGEb7jdLVSSW0uQOWuBOAYndB H5NVYUhIXuBK2ElA8qQQuouy2cvjQBDLje62gjOha5WuUjyLjwiGSxBfWGh9oSdZm8Gn 3dJw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:cms-type:message-id:date:subject:cc :to:from:dkim-signature:dkim-filter; bh=5Scyun2f9vAe7f2WluCnvJycg0mdcot342qdWyjo0WU=; b=HYXUNxaghtsgs2uTDwsr9PiaISnr0BgdycuWWW4CvyFjeBP46gmHmusrh+AbadWxjq Hs4ZjMZr91LyQgm9bpVpWzO6J/9UTx/e6Gqdu32YdWd8I/6nwZalSNWmP4FJnZ4dNupf aNypKPHSgUkodcjYpmgy3coRqiMeUbcaTM8qr9QkphtQSjHrDvwRtjBA2l0jLBGvKUIO 8UFTIPinmOY6IGHOFTWYdbxErDj1UaZU+CwPUkv6q8LUbLz6iwe00/5UxR9E2c/BjHHj DHTQq/fliXqeOICicOYXmnMLFeOkbUzafVyRVmN2sNrsgxZOhx3rBiyF1dFF1l7yatZn +7xg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@samsung.com header.s=mail20170921 header.b=iIG7Fu0S; 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=samsung.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id c24si8126242ejj.646.2021.09.06.05.29.57; Mon, 06 Sep 2021 05:30:21 -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=@samsung.com header.s=mail20170921 header.b=iIG7Fu0S; 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=samsung.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242193AbhIFM2C (ORCPT + 99 others); Mon, 6 Sep 2021 08:28:02 -0400 Received: from mailout2.samsung.com ([203.254.224.25]:52505 "EHLO mailout2.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242100AbhIFM2B (ORCPT ); Mon, 6 Sep 2021 08:28:01 -0400 Received: from epcas5p3.samsung.com (unknown [182.195.41.41]) by mailout2.samsung.com (KnoxPortal) with ESMTP id 20210906122655epoutp02269514ef4f930f5aef8c00d426d33b0b~iO0yUS0aj1221612216epoutp02v for ; Mon, 6 Sep 2021 12:26:55 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout2.samsung.com 20210906122655epoutp02269514ef4f930f5aef8c00d426d33b0b~iO0yUS0aj1221612216epoutp02v DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1630931215; bh=5Scyun2f9vAe7f2WluCnvJycg0mdcot342qdWyjo0WU=; h=From:To:Cc:Subject:Date:References:From; b=iIG7Fu0SBAeEzQervBTMcLfcy4eoakaA1f3uEi3Fh4UQQDpDX2xOSUfnLIBQDQ7y6 WgYjURg6hu2EnxkmhzJT9SKVhwTmrKDbxdV1XqpAv7B9Rb52euYU3Q9w4cPqoBgC/K 8/Nzg4YPmuklhEeyqcYkLlMZ88DEMxQdFcj6nKq8= Received: from epsmges5p3new.samsung.com (unknown [182.195.42.75]) by epcas5p2.samsung.com (KnoxPortal) with ESMTP id 20210906122654epcas5p2291014d722a311ab307eb76bb9807f9c~iO0xxhn0B1400014000epcas5p2Q; Mon, 6 Sep 2021 12:26:54 +0000 (GMT) Received: from epcas5p3.samsung.com ( [182.195.41.41]) by epsmges5p3new.samsung.com (Symantec Messaging Gateway) with SMTP id 10.23.38346.E0906316; Mon, 6 Sep 2021 21:26:54 +0900 (KST) Received: from epsmtrp2.samsung.com (unknown [182.195.40.14]) by epcas5p1.samsung.com (KnoxPortal) with ESMTPA id 20210906122653epcas5p19c46576f0be4d4a101f851a751addde8~iO0wrC_mF0552505525epcas5p1A; Mon, 6 Sep 2021 12:26:53 +0000 (GMT) Received: from epsmgms1p2.samsung.com (unknown [182.195.42.42]) by epsmtrp2.samsung.com (KnoxPortal) with ESMTP id 20210906122653epsmtrp2884f31c37a01b0e1f0a412fb4e307975~iO0wqQt-71366813668epsmtrp2Z; Mon, 6 Sep 2021 12:26:53 +0000 (GMT) X-AuditID: b6c32a4b-251ff700000095ca-c8-6136090e5274 Received: from epsmtip1.samsung.com ( [182.195.34.30]) by epsmgms1p2.samsung.com (Symantec Messaging Gateway) with SMTP id 35.E5.08750.D0906316; Mon, 6 Sep 2021 21:26:53 +0900 (KST) Received: from localhost.localdomain (unknown [107.109.224.44]) by epsmtip1.samsung.com (KnoxPortal) with ESMTPA id 20210906122651epsmtip12adac5912126f63ce2592241171f4ca8~iO0vMCalX3207332073epsmtip1a; Mon, 6 Sep 2021 12:26:51 +0000 (GMT) From: Ravi Singh To: hannes@cmpxchg.org, mingo@redhat.com, peterz@infradead.org, linux-kernel@vger.kernel.org Cc: a.sahrawat@samsung.com, v.narang@samsung.com, vishal.goel@samsung.com, Ravi Singh Subject: [PATCH] psi: fix integer overflow on unsigned int multiply on 32 bit systems Date: Mon, 6 Sep 2021 17:55:24 +0530 Message-Id: <1630931124-27197-1-git-send-email-ravi.singh1@samsung.com> X-Mailer: git-send-email 2.7.4 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFjrNIsWRmVeSWpSXmKPExsWy7bCmpi4fp1miwZcnchYXd6darN7ka3F5 1xw2i0sHFjBZHO89wGRxaRGLxaGTcxkt1t0+zejA4XH4zXtmj80rtDze77vK5tG3ZRWjx+dN cgGsUVw2Kak5mWWpRfp2CVwZXw6+ZS34zVXRe/0oSwNjI2cXIyeHhICJRMvyFcxdjFwcQgK7 GSUmXlrEBOF8YpQ433OBDcL5zCjx5+ZeoDIOsJalOz0h4rsYJVovP2UGGSUk8IVR4soxNRCb TUBL4tHVP4wgtohAnMSDe7+ZQHqZBQol9ry0AwkLC4RL/Fr6GqyERUBVYuOJN+wgNq+Au8Ss f5tZIK6Tk7h5rhPsOgmBTewSm7bPYINIuEicvnaLHcIWlnh1fAuULSXx+d1eqJpqid6+rVDN HYwSW9vPQBXZSzy5uJAV4iBNifW79EHCzAJ8Er2/nzBB/Mgr0dEmBFGtKvFj+nqoTmmJxRc/ sELYHhI7Tl+Hej1WounLZrYJjDKzEIYuYGRcxSiZWlCcm55abFpgnJdarlecmFtcmpeul5yf u4kRHN9a3jsYHz34oHeIkYmD8RCjBAezkghvtLNRohBvSmJlVWpRfnxRaU5q8SFGaQ4WJXFe 3VcyiUIC6YklqdmpqQWpRTBZJg5OqQam47nNDDVLPfaz7xS/9LEuX/ml5qet8053v4oT43x/ /99HHSW3XCcVWxF+lhMWVWdOd29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mu07a5LEMPsTZ+UuB4+a/KSKc0MW5CcwHxslatZQ2x/YEnP//W9 zNsXCTDfvezFtJVfibert+CMtvU2xTPBBgl/9gVefcd309at5NfGTVKqyw+eyc6vDLiqxFKc kWioxVxUnAgAPJbH/pECAAA= X-CMS-MailID: 20210906122653epcas5p19c46576f0be4d4a101f851a751addde8 X-Msg-Generator: CA Content-Type: text/plain; charset="utf-8" CMS-TYPE: 105P X-CMS-RootMailID: 20210906122653epcas5p19c46576f0be4d4a101f851a751addde8 References: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 Signed-off-by: Vishal Goel --- 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