Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp2424574ybi; Sun, 9 Jun 2019 11:26:07 -0700 (PDT) X-Google-Smtp-Source: APXvYqzuuazWe4/Fiu/BWlRS/YY3U1qj+wZbqUT3/jwgEsYUnaZk7cYo+Vp1V/66oUQuVys89H+v X-Received: by 2002:a63:514:: with SMTP id 20mr12272353pgf.272.1560104767121; Sun, 09 Jun 2019 11:26:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1560104767; cv=none; d=google.com; s=arc-20160816; b=vG7ntFkXMdufiRQvrPL5uBkDpJyqS4/HYBfB5MuIuZb0p+QnaO8GUhaq3r86fpu+Cd fAh+VV89RIB8x+hNbmipID2RUe+6Aq2fnk0ijFxVKnH5XbQYYS/0Ic8eQFsLxqhuYAgR Js3kJ0wKqoE7/eiOtCO93ynQmrre2rk+hDGnWEXHJSN//KhfMbsyqDuChGHpVGzmX8XR UpVhR1vJZ5favh9S4T6S10B2ScWORcSM/fwsfEGMPf2vMR/66UkRzDpKcQ6qTJ5Hua6B 01xGZ2RKWXavlJO2gnUihAa+va89aOSkZBfcHI/Eq5Pmr7pHfB8Sh6wvS4Ekas2pypGu PmJA== 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=uDkXiOkMYC9pNGLfxndbSVqiwy7B/sjeeOCbdEy9Ad88grun2wnf3hikcDNaUIuWSw CDg10H+nzMuZJWZfRjV+9tLHR4fK42acXWkvHteKxDFVtk+t2BDVAkP5w5SVhRwoZWKl ZN19CFW9S+Pa+atDOHu+fJC58mU/CO+MQLAEmRmQukyUzkRwXkuWVzFK07OrbgIFmILV R/PTBlTQndGUPxwedGG+Oyi6DKxca5CiOODWax9R7tDkQJfllrFMIgfq4PAbM9B4sgxr Z0Dh9jIq2B1jRh76nYnLNsChdBcyhnZ+V89lOHvguv+aT5+qrKqXrgqViQbGfPK60nQu qkPw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=YhDPY6ob; 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 a18si3574373plm.171.2019.06.09.11.25.50; Sun, 09 Jun 2019 11:26:07 -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=YhDPY6ob; 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 S2389026AbfFIRG3 (ORCPT + 99 others); Sun, 9 Jun 2019 13:06:29 -0400 Received: from mail.kernel.org ([198.145.29.99]:46174 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389002AbfFIRG1 (ORCPT ); Sun, 9 Jun 2019 13:06:27 -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 D8B69204EC; Sun, 9 Jun 2019 17:06:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1560099986; bh=XbF+Fbw0YUo7hx0ywMUR4QLETQp349Wrkcg+6+6D23A=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=YhDPY6obbKM6jd7NWV3gIHDbysgKmAkbA3bD/55Mp1QJfyNk13x2X0XAnlsK7rqHu EeOrKj5MkW+RN3x1W/ElKMuzKeUU2Pii/rmuIKf31I7acXXhDVSfZsVxev1+HewHpz B5/yonNR5Ovah6KRdReje962LfsiSlMXcWBRkrns= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Dan Carpenter Subject: [PATCH 4.4 238/241] genwqe: Prevent an integer overflow in the ioctl Date: Sun, 9 Jun 2019 18:43:00 +0200 Message-Id: <20190609164155.652936299@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190609164147.729157653@linuxfoundation.org> References: <20190609164147.729157653@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,