Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp818686imm; Wed, 26 Sep 2018 07:17:11 -0700 (PDT) X-Google-Smtp-Source: ACcGV602k/ZEJdc6uDitYL00qHKeHmuxB0K/oJ2ih3vcYtXrgi2QDh9u3WVFUiFgh6vU4s8r4Lha X-Received: by 2002:a17:902:6ac4:: with SMTP id i4-v6mr121445plt.153.1537971431139; Wed, 26 Sep 2018 07:17:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1537971431; cv=none; d=google.com; s=arc-20160816; b=v9NE1PV9PcZ68TR6f+5838SKfZadXp1IyMWwdgbmTfcPj7wOf1tOsfvbJWCTLIR12u jyb+UNFNMBxLC7rSYXIRVqjgKGPgnVNb5FVM84WYMPcDof09X9pLzDTiyEMswbT1bQbJ tShG8pb6TVC7rYYllpPEsJJPGsdTJFOX9paSRHF/Qcl+zMU1H39/w+ZYriQ6Wj36nGz7 dWe8hxFUwBeesiAHwOoG5z/3lYNIApfyzHewfg5Qm2Yr2083HB4TyXOwhoU0GcNSp1qc 3cemW5ffTvKh2IJ3mdwFobJY2oiLo495sFY6CVZmoc5BN9yWfI3FkP0T5Juntk5BtHaA GsiQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=J05zKTNn2Y/+M4Dr898zqUw6g0HICBbnSSgbu+L2HHQ=; b=Wfzn/Uld29PN7EaabVyRmJkdCBLu4OnAKITugWLE2CiD6v4iz0WIbqtFtXA+itQJOn EnrSfDKqAKF50s5WybDva3b98o8sVBvpwQ6sCL6lXkDBWbtG2AfCk/xtJ5geBS9CU1WN 47geFFb0OtnQ871WvFFq30uiqV/l4w8sqtHpo00efIy/9sPfVQUJk2vkjhiht/OG2mUg em36siYgD5rwhCEupgSZqKXvbOjTAEro7Vpq7fFQaiGHr3PaJtMeZ/yW5s1NEy87Do0y wyoBbZ5cGifMV7R3Xqr/8u9p/7ooJuJ4p5CW4zUEGcTBbMLE/cONWtENW0wyUj6IaaaA vrzA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ursulin-net.20150623.gappssmtp.com header.s=20150623 header.b=YV3qXhhK; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id u8-v6si6137423pfj.137.2018.09.26.07.16.55; Wed, 26 Sep 2018 07:17:11 -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=@ursulin-net.20150623.gappssmtp.com header.s=20150623 header.b=YV3qXhhK; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728212AbeIZU3w (ORCPT + 99 others); Wed, 26 Sep 2018 16:29:52 -0400 Received: from mail-wm1-f68.google.com ([209.85.128.68]:53182 "EHLO mail-wm1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727587AbeIZU3v (ORCPT ); Wed, 26 Sep 2018 16:29:51 -0400 Received: by mail-wm1-f68.google.com with SMTP id l7-v6so2483040wme.2 for ; Wed, 26 Sep 2018 07:16:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ursulin-net.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=J05zKTNn2Y/+M4Dr898zqUw6g0HICBbnSSgbu+L2HHQ=; b=YV3qXhhKBy4l4H8m06ErtKrlCnSUbIyTr0XuQ72d+vMzBCI5vY/uQM8N6zCjNJo2sn LxMmWyZuy+cnPwvwQ7pVcEG3q2LVyvMP2eSfD9Fel4jxNUtBg9yTK2KFmZF7uU4MC8/E GDGe7hhUCRKeeFmTk6Hp00MQv1LoqKMukqciOZRMlWgpekgWGpS8FFYeMei7ys1xH8r0 JpEIo2rHmsyOrRhnXq+bFSDWnvQjmoLZOpnLJPkCe1jHSSV4uCL0L76ZQ2H570cbifJP hCWSURv6JCt/dEbnhaAIZmCd9Zg+caTAWXqhnM/ZDN071HWHYW6flSnAQg9IA5c892YE f/5g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=J05zKTNn2Y/+M4Dr898zqUw6g0HICBbnSSgbu+L2HHQ=; b=IT5sH/xV1zsV4cbe7FdavrefBRhjXtp9+tI2V9jEom6tzlmKKXBCHW7TswO5NVlxky RotaBLgi2A4yxCkgn8UslcwsUuzRgKXy5C3psSpD4HUlCJHpS7B//Yw7/vDIHLZyUZIx N4bBTLbwPbxq8mbTHC+JW3Zeg3x3oSLDPawc9JLsfoW9GFNdP5pULR5mPMOLGp0Ws1PQ hPl+trm1+SeI1Fmdu4xN0NFSG3j43X+WguvM6+tLBpauTdf7c3+xb3qe+w+xyOiJaGL/ 6CfCkyudXM6he3GAGF7f7EtPbItNIrWBakQ/+RQYnyU1DKH/Cf0ZDeLhzV1wQW2Ei6F3 rwYQ== X-Gm-Message-State: ABuFfoghVqpo2akFZHmPOJWUzCfGvQEoVo4oGwD67oe5CJlkDXoD1qBQ E5DH3ni61Q67XJxefy9JtttIN6burPI= X-Received: by 2002:a1c:6543:: with SMTP id z64-v6mr4758611wmb.57.1537971399868; Wed, 26 Sep 2018 07:16:39 -0700 (PDT) Received: from localhost.localdomain ([95.144.165.37]) by smtp.gmail.com with ESMTPSA id v14-v6sm3209974wmh.41.2018.09.26.07.16.38 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 26 Sep 2018 07:16:39 -0700 (PDT) From: Tvrtko Ursulin X-Google-Original-From: Tvrtko Ursulin To: linux-kernel@vger.kernel.org Cc: tursulin@ursulin.net, tvrtko.ursulin@linux.intel.com, Tvrtko Ursulin , Bart Van Assche , Hannes Reinecke , Johannes Thumshirn , Jens Axboe Subject: [PATCH 6/6] lib/scatterlist: Fix overflow check in sgl_alloc_order Date: Wed, 26 Sep 2018 15:16:25 +0100 Message-Id: <20180926141625.17727-7-tvrtko.ursulin@linux.intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180926141625.17727-1-tvrtko.ursulin@linux.intel.com> References: <20180926141625.17727-1-tvrtko.ursulin@linux.intel.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Tvrtko Ursulin It is necessary to ensure types on both sides of the comparison are of the same width. Otherwise the check overflows sooner than expect due left hand side being an unsigned long length, and the right hand side unsigned int number of elements multiplied by element size. Signed-off-by: Tvrtko Ursulin Cc: Bart Van Assche Cc: Hannes Reinecke Cc: Johannes Thumshirn Cc: Jens Axboe --- lib/scatterlist.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/scatterlist.c b/lib/scatterlist.c index 581a2e91e515..c87243d46f10 100644 --- a/lib/scatterlist.c +++ b/lib/scatterlist.c @@ -485,7 +485,7 @@ struct scatterlist *sgl_alloc_order(unsigned long length, unsigned int order, nent = round_up(length, PAGE_SIZE << order) >> (PAGE_SHIFT + order); /* Check for integer overflow */ - if (length > (nent << (PAGE_SHIFT + order))) + if (length > ((unsigned long)nent << (PAGE_SHIFT + order))) return NULL; nalloc = nent; if (chainable) { -- 2.17.1