Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp2360595ybi; Sun, 9 Jun 2019 09:50:49 -0700 (PDT) X-Google-Smtp-Source: APXvYqz8J6GGbyEM5AuK9SYTEVYRdGuJIodaDeLxKnMDLsviR8nx/DEccs6G6is4XcDhEzQGGDoq X-Received: by 2002:a62:1456:: with SMTP id 83mr18621129pfu.228.1560099049264; Sun, 09 Jun 2019 09:50:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1560099049; cv=none; d=google.com; s=arc-20160816; b=x1OJaL2wtQu6aQma7MrqV1WJ/JPu2Ll8RejusGqspm5Hcm75eKU8dk4z4UkO70TPNp 0rH1WsqK3kjMpNgQkV4Zza3mfwpgM+kLI+AkYdT8HCV2kU9Bo3Cu6DG9Jkb045maBVPv slOo5h4RsrMkUSi2imRye6NnrAb4KHWEZcMbp0eZMsdK5Th3gM4MAuTVHG0vI6dyZDK3 97/pCoX5IPHeElg+nAPsDvhvZ0JuOyJSqeq8PosXAZTYNpYj98UepFIZHvU1OoSLUfRd nkXBy+jTVQ4K/kuYY6Tjkc97pd5R1NVYMwXitR31/+sTuj+UariK0aXk54O60SX7GcUV TUAA== 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=gu6uHQyT3dXWVWb6em16MaseT6oLJojnl8V4xuv+yIU=; b=KCFj+Sf2VuSo1Y4MwNxDONQeIwm82pOibjIBD8Remn4fhOnvUTFt3JC7vQDNxn3c1o rBgrKIM4i/Y8xwzx7ogAnvmyJ5Uuzj+NEKd9si7BmZcVNcgm3GHU3JHeROwmI/yewAK7 CcPkjCvamrkL3g42ELeH5JGd+VMxUEMyzV686Bc5HVgkhgwUamA6U9f7t4YmoqihXQby nzhtsqt30ZsgXcZkae9MNPJfl84GF+u7pQBkIo4Tyb5il0uWkwnoeBcTAhtfrki+T41S OtQun7pMk0WDgIDfTHc84hsJrExMvfJ2JYvXkM8O6Xp6356cyTytzSmrTKEusEMRHZa0 lPXg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="hS/7FOgg"; 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 y11si6498587pll.213.2019.06.09.09.50.33; Sun, 09 Jun 2019 09:50:49 -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="hS/7FOgg"; 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 S1731272AbfFIQsm (ORCPT + 99 others); Sun, 9 Jun 2019 12:48:42 -0400 Received: from mail.kernel.org ([198.145.29.99]:47846 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731232AbfFIQsk (ORCPT ); Sun, 9 Jun 2019 12:48:40 -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 B5799206C3; Sun, 9 Jun 2019 16:48:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1560098920; bh=c/h5LsyEMrg8LMhNb60YT3K6SWopq5tpLSzjqwcrkdQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=hS/7FOggIOFtGyGR8TCCaaHqdWStk9gk41Bzj27i1W7dOA94lLUUCJXyGPYv7lxoR 9zHWR7Zy5WLbIe/pvMeFAUS9OgMVhZvg0cjih35UJfahKdDF64naqGohaFSlsfpiWM kdyP1oiTBbUzfehUBW0qolgD0Qn4SbEbXhOt/LEE= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Dan Carpenter Subject: [PATCH 4.19 35/51] genwqe: Prevent an integer overflow in the ioctl Date: Sun, 9 Jun 2019 18:42:16 +0200 Message-Id: <20190609164129.413681866@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190609164127.123076536@linuxfoundation.org> References: <20190609164127.123076536@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 @@ -780,6 +780,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 @@ -587,6 +587,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,