Received: by 2002:a25:824b:0:0:0:0:0 with SMTP id d11csp1194545ybn; Wed, 2 Oct 2019 12:14:57 -0700 (PDT) X-Google-Smtp-Source: APXvYqzSyPQeXw8NQy84fmW7YdBTBHLrEZ6BUJhYE1jUxqu1CzJCSOowsHi4QSVWI/qfoDGtPUg2 X-Received: by 2002:a17:907:411d:: with SMTP id nw21mr4402334ejb.8.1570043697144; Wed, 02 Oct 2019 12:14:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1570043697; cv=none; d=google.com; s=arc-20160816; b=zG2EA7Mh3pwdTnXrfXoCoEt6NrXdybTGJHHRKUAcSsHPBKrEU+K6NFAiDIUIIFVX8t YZ1sKBmId9UVVHy0BAskerc9MYSC9gozmpA3f/UphsMsHAPFrg5qB+zIUWNdC2bCMFaj vhJoTCahUeJvhWrYJmaXIy51FQr0uj3MG/+pJ4DRHS2NELKE7rnCC0mIQunNI5Xrd9Yl my+5qpS2t7uHrKlGwSFTUGoU6dVerATH1XkFcqFHoXSB0dL2Q9yIMhBW1litXsVceAPm s9/4bffIstakd8XeYCejj8M3xIt1mhiPUxxJpfrznAOR8Del4Ag7N+ySE2AScJpFX+jR CBqQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:subject:message-id:date:cc:to :from:mime-version:content-transfer-encoding:content-disposition; bh=umukOgRKR+o4uszuYAKyT7bAa/JYaUirkcDxU5A0YR0=; b=V9OaaoAYZgACBDOQMKtvP37lpFAybzC4bcSTYxb4ypR4Q4gfsq3KPbkkUfEXgQIBuI ug8RE/N3WoD2yxIHsh6oKMox9jM4Ge6B3aUFxejS/GQWJ0wnjM2ZVyNTPgHZXuSJcqGg 15kvp51caWFhKb2vVYBudgomNbpjzEzCFJxC54r2XZetZJiNa7TrFtI8wqlOQCsLrrDX ps0MHygu4HtvXhQoHEC6tqfBPhb4eijRBwNs2sc0/PS0x3rPzOl/UJzmSbz4dbeyR8MY gsjx3Z3SoMiux9L6ohRZ6uw+4zQx6ciRLW7x2T6BRJ2ldUbElj3KSj5VoQFCOeiCdjbx jLJg== ARC-Authentication-Results: i=1; mx.google.com; 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 jr6si6906ejb.307.2019.10.02.12.14.32; Wed, 02 Oct 2019 12:14: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; 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 S1730182AbfJBTNP (ORCPT + 99 others); Wed, 2 Oct 2019 15:13:15 -0400 Received: from shadbolt.e.decadent.org.uk ([88.96.1.126]:35334 "EHLO shadbolt.e.decadent.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729086AbfJBTIJ (ORCPT ); Wed, 2 Oct 2019 15:08:09 -0400 Received: from [192.168.4.242] (helo=deadeye) by shadbolt.decadent.org.uk with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1iFjyo-00035v-ED; Wed, 02 Oct 2019 20:08:06 +0100 Received: from ben by deadeye with local (Exim 4.92.1) (envelope-from ) id 1iFjyn-0003c0-Pq; Wed, 02 Oct 2019 20:08:05 +0100 Content-Type: text/plain; charset="UTF-8" Content-Disposition: inline Content-Transfer-Encoding: 8bit MIME-Version: 1.0 From: Ben Hutchings To: linux-kernel@vger.kernel.org, stable@vger.kernel.org CC: akpm@linux-foundation.org, Denis Kirjanov , "Dan Carpenter" , "Greg Kroah-Hartman" Date: Wed, 02 Oct 2019 20:06:51 +0100 Message-ID: X-Mailer: LinuxStableQueue (scripts by bwh) X-Patchwork-Hint: ignore Subject: [PATCH 3.16 27/87] genwqe: Prevent an integer overflow in the ioctl In-Reply-To: X-SA-Exim-Connect-IP: 192.168.4.242 X-SA-Exim-Mail-From: ben@decadent.org.uk X-SA-Exim-Scanned: No (on shadbolt.decadent.org.uk); SAEximRunCond expanded to false Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 3.16.75-rc1 review patch. If anyone has any objections, please let me know. ------------------ 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 Signed-off-by: Greg Kroah-Hartman Signed-off-by: Ben Hutchings --- 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 @@ -779,6 +779,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 @@ -571,6 +571,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,