Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp2414914ybi; Sun, 9 Jun 2019 11:10:57 -0700 (PDT) X-Google-Smtp-Source: APXvYqxQzqanPsfVjCRLkQP+e++lP/RCYu6TG+s6pghnerHPySRHuCW2hqhjnN0DPxRYHII42W9V X-Received: by 2002:a17:902:e409:: with SMTP id ci9mr66816088plb.103.1560103857300; Sun, 09 Jun 2019 11:10:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1560103857; cv=none; d=google.com; s=arc-20160816; b=X8aXwDCoZUP0ms5AehIaACgDabek4yu/Lnez+KpiJNtWuHiQCrAjkq8jkZvmJzYgK5 v7VFPHavBRUxqlLX5FWRWXfs5fTg7CFRhc2CPtI+XFPN8nzoDAiQzeubMuxdiiaFS97s yqVYo/db+HK0HKrxhuTUctH3sO8iIBeCo38p80ru98xh+N4dE5I8cBMEn/xx7IML7QV/ RAPruYQdouou+8PN/oCn2CCAtv/knClFAEXwykYwwwbOLfTXSB7LmtZnYkswJAl6e6TI XhJNYOQt4zQfK/oQIXIqqSPpmGKOuxoy5j5YVJiTKl4KWeH3tXhknOF7yl3bVQNduqse 3r+w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=eonzdGfAyxnXdKtjOukzXZfazKxLARfvyJFLHR88lKY=; b=0LjpHV50xYuvQBB+3wNaxd6efCYCOKBbO0we90CCxTiFAOqddJfveQc+4Eut5LxXuN sGJENoyTV4tGOPNCANWJUqhmKWWwQJJJ2TgP7dTIsUaL942N62EkULG5jUpVZs+K0Snq 9iL/VgFOotTgULhr5ajO0/sASUw4QbhWNi1s3E1dxiOaULDUhp6OJCBEBPM/Ewdy+2f0 LwQ63Wa2k8aKs/ZP29infhRlvwqzesCHei2U9FJ1thcNEtGseNxFQViXOqATYPaWDmM3 kQMluWXNMc5eKFEptNP1CP3nn3NhuGXTGz0tLQs76wZSIHbvRslIoNwN6fcUVS634oUu 8LEQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=r2FjtMsS; 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 z61si8391440plb.19.2019.06.09.11.10.41; Sun, 09 Jun 2019 11:10:57 -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=r2FjtMsS; 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 S1732697AbfFIQyt (ORCPT + 99 others); Sun, 9 Jun 2019 12:54:49 -0400 Received: from mail.kernel.org ([198.145.29.99]:56638 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732683AbfFIQyr (ORCPT ); Sun, 9 Jun 2019 12:54:47 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (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 9F708204EC; Sun, 9 Jun 2019 16:54:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1560099287; bh=XbF+Fbw0YUo7hx0ywMUR4QLETQp349Wrkcg+6+6D23A=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=r2FjtMsSA+Gm7ezPy3LVGaKkcJR+JOw1vd68cdlMzXDMJ7/tH/EeBpZwoK4HHFdjG qav9Xg+RmVSJJgTi7x/sPwo6RDcE1G9aBxXqzjj492dzdIZJE2Vx63SmPPVyFB2B8J aqbTScTFEv3UixGHHfqzS7A4XY0Adv7XzPrdapTw= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Dan Carpenter Subject: [PATCH 4.9 77/83] genwqe: Prevent an integer overflow in the ioctl Date: Sun, 9 Jun 2019 18:42:47 +0200 Message-Id: <20190609164134.500864352@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190609164127.843327870@linuxfoundation.org> References: <20190609164127.843327870@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Dan Carpenter commit 110080cea0d0e4dfdb0b536e7f8a5633ead6a781 upstream. There are a couple potential integer overflows here. round_up(m->size + (m->addr & ~PAGE_MASK), PAGE_SIZE); The first thing is that the "m->size + (...)" addition could overflow, and the second is that round_up() overflows to zero if the result is within PAGE_SIZE of the type max. In this code, the "m->size" variable is an u64 but we're saving the result in "map_size" which is an unsigned long and genwqe_user_vmap() takes an unsigned long as well. So I have used ULONG_MAX as the upper bound. From a practical perspective unsigned long is fine/better than trying to change all the types to u64. Fixes: eaf4722d4645 ("GenWQE Character device and DDCB queue") Signed-off-by: Dan Carpenter Cc: stable Signed-off-by: Greg Kroah-Hartman --- drivers/misc/genwqe/card_dev.c | 2 ++ drivers/misc/genwqe/card_utils.c | 4 ++++ 2 files changed, 6 insertions(+) --- a/drivers/misc/genwqe/card_dev.c +++ b/drivers/misc/genwqe/card_dev.c @@ -782,6 +782,8 @@ static int genwqe_pin_mem(struct genwqe_ if ((m->addr == 0x0) || (m->size == 0)) return -EINVAL; + if (m->size > ULONG_MAX - PAGE_SIZE - (m->addr & ~PAGE_MASK)) + return -EINVAL; map_addr = (m->addr & PAGE_MASK); map_size = round_up(m->size + (m->addr & ~PAGE_MASK), PAGE_SIZE); --- a/drivers/misc/genwqe/card_utils.c +++ b/drivers/misc/genwqe/card_utils.c @@ -582,6 +582,10 @@ int genwqe_user_vmap(struct genwqe_dev * /* determine space needed for page_list. */ data = (unsigned long)uaddr; offs = offset_in_page(data); + if (size > ULONG_MAX - PAGE_SIZE - offs) { + m->size = 0; /* mark unused and not added */ + return -EINVAL; + } m->nr_pages = DIV_ROUND_UP(offs + size, PAGE_SIZE); m->page_list = kcalloc(m->nr_pages,