Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp2362144imm; Mon, 28 May 2018 06:45:05 -0700 (PDT) X-Google-Smtp-Source: AB8JxZoEbWGLKcRza+n2OHsFRzEob+9O9lpU4GT9sDCCUr9ds8drMQ2Kq/pNigga6jgvL6sR89Y4 X-Received: by 2002:a63:b91b:: with SMTP id z27-v6mr10640070pge.240.1527515105528; Mon, 28 May 2018 06:45:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527515105; cv=none; d=google.com; s=arc-20160816; b=YZBr86C/U2TynnNvGwESlzSfOahw8P320itTeuhTIR46UVqdzBqwOxmRClzjFb1R9H uVb7ZbYXfYSdAtGfGLmrz2h6T0pj3EWjsnK77ItPzYAvGKINiTkX9LR2q0HgmFgzMpZ7 L3ZqfyNC2ptxBlUZkQTY7mJSH0ntDyRJNUOjFDUY4R97RpMH8b4HIwzq+VxMKENxj4Bd 3RCHRb4aZrJHy7xhtC1XmxfakZacytkydoUD16CVArU5MgNIYqmqdL2Q0scEGF0QHyWF WTFZBsIJ2Zy7Hxd6dMn/TWR0OVMVV9GQhUrn9XDNvBCi/sC+uy/xau6Q+usUDKe+Eyel 0ATw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from:dkim-signature :arc-authentication-results; bh=L0/Cq+A2h5YMiBeOv5Y9wbpYRopczIj3yb/NnRn4DVk=; b=qqYk2oBttBYDEUsSFgnmaqo9+gaj4Vq6/S39rjOyeQFBz1sSOlyVhpdpSub94zBnXm vZdR33gB9C100gO1n2IboMThIo5v6Sx/Txv3aWgkfhVgmQQCutaA3KSU+L05yspJNRQu JzRFiGugyBKdhSP4olj++vNrAFwJsTz6equkMPwWiC9PJTC5iRlFX7Ck7YlDWByS9yz5 iucvbfMUxwOXqN/QHIMdmyoanro4+7rvzrK2ah9B+SZHRllZ8i7Ow+lL1Udk43LQP18W EwDgzSYE4fbaBoFWwyv68WMrXMmDGlpa5QPBkXsnogZVXWX5rYMenjmZDClu7bqtsDf4 ymUA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=JJu8Wqhh; 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 d3-v6si19885206pgv.562.2018.05.28.06.44.50; Mon, 28 May 2018 06:45:05 -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=JJu8Wqhh; 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 S968884AbeE1Knx (ORCPT + 99 others); Mon, 28 May 2018 06:43:53 -0400 Received: from mail.kernel.org ([198.145.29.99]:34702 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S937621AbeE1Knr (ORCPT ); Mon, 28 May 2018 06:43:47 -0400 Received: from localhost (LFbn-1-12247-202.w90-92.abo.wanadoo.fr [90.92.61.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id B51FE2086D; Mon, 28 May 2018 10:43:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1527504226; bh=Df3R/Apmwi1n+JjrdLrfkTbsyYwP2we4fIzGgOpa43o=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=JJu8WqhhSs6Y7Txu5U9N2ow8PGQB/lQsKuiz4PdmtsRnAasprKd7BnA++9gk02jWp dfCnB0/bDD7Tgp0SS+ET06BOozFVyK9o42P7e+11Dv5XVgthXzMrg+U7GfVIV0rPvI uWesITIykwqi/5msUU+UmB0MH9++CZ7M97gFE8l8= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Eric Biggers , Jason Wang , "Michael S. Tsirkin" , "David S. Miller" , Sasha Levin Subject: [PATCH 4.14 060/496] ptr_ring: prevent integer overflow when calculating size Date: Mon, 28 May 2018 11:57:25 +0200 Message-Id: <20180528100322.322739392@linuxfoundation.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180528100319.498712256@linuxfoundation.org> References: <20180528100319.498712256@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.14-stable review patch. If anyone has any objections, please let me know. ------------------ From: Jason Wang [ Upstream commit 54e02162d4454a99227f520948bf4494c3d972d0 ] Switch to use dividing to prevent integer overflow when size is too big to calculate allocation size properly. Reported-by: Eric Biggers Fixes: 6e6e41c31122 ("ptr_ring: fail early if queue occupies more than KMALLOC_MAX_SIZE") Signed-off-by: Jason Wang Acked-by: Michael S. Tsirkin Signed-off-by: David S. Miller Signed-off-by: Sasha Levin Signed-off-by: Greg Kroah-Hartman --- include/linux/ptr_ring.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) --- a/include/linux/ptr_ring.h +++ b/include/linux/ptr_ring.h @@ -450,7 +450,7 @@ static inline int ptr_ring_consume_batch */ static inline void **__ptr_ring_init_queue_alloc(unsigned int size, gfp_t gfp) { - if (size * sizeof(void *) > KMALLOC_MAX_SIZE) + if (size > KMALLOC_MAX_SIZE / sizeof(void *)) return NULL; return kvmalloc_array(size, sizeof(void *), gfp | __GFP_ZERO); }