From patchwork Wed May 9 00:42:21 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kees Cook X-Patchwork-Id: 10387827 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 9ACD360556 for ; Wed, 9 May 2018 00:45:38 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7012F29095 for ; Wed, 9 May 2018 00:45:38 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C8007291C5; Wed, 9 May 2018 00:44:34 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.3 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from mother.openwall.net (mother.openwall.net [195.42.179.200]) by mail.wl.linuxfoundation.org (Postfix) with SMTP id 1445529607 for ; Wed, 9 May 2018 00:44:20 +0000 (UTC) Received: (qmail 21516 invoked by uid 550); 9 May 2018 00:43:01 -0000 Mailing-List: contact kernel-hardening-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Delivered-To: mailing list kernel-hardening@lists.openwall.com Received: (qmail 20345 invoked from network); 9 May 2018 00:42:56 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=kacq6440mdTwv10+JXG8+ILiqdEXJe+Qny7L57GcEUI=; b=HrIc2zBpMlKCaD303NPVf5xNwccD63d6byjHONBlTfRaozEoYFQVPWYnAICxIJoZyK Ok6aHjkCIS7J4kJZMId6UzdfKJEOk1zxh1b3LDrGTQk/dv7Ae4Czh2QfOBmaEQPH+27N H0zjttfhDbQq889l8qPS9qYT5Lm9CgPoRqwas= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=kacq6440mdTwv10+JXG8+ILiqdEXJe+Qny7L57GcEUI=; b=V4W0cFcfVMyr54bXQzXxdbYdpz5vcwPXtKQGHTIFsaY1t4kWxE5KKwkFgAkzjqamRB 78DYFd2LirFS/dlFBS5D9PST0JCzMWasISoGj/VZTvCumAeb7rIc4oOSJTUJUBaDHHgT hcXaLKiH5Rpu7Smj1wtnTMVTYTPZVUXMTjSfr/7cIY5Kd5M/rbXUU2FkjTWIsZ64GGZz M8tsVS66PRyciTRDTzfTzPNXfz9lQxr6Ro1Qc6Wfp7Ie3E0E7PupJq3cxs2DvQ3hp+j0 lIFCk0nCPbgh/vkOHBTs233YK3zb9HhLlhlzTpzvsFqhV3oOmVHJQq9pDVKT/CIa5v/1 YnVA== X-Gm-Message-State: ALQs6tD4XlcuKWTgy3nX/N9ZMZ05wGL5juaOXyqeIveZeEfPTNPhQ1Wc J8DodHV7wDbKN976u3xxgtvBEw== X-Google-Smtp-Source: AB8JxZpp5Rwf49tLxkQMoP9hyCo2xHoMK0tV/97awXn0+pSfChRwTi2tF9r8BjKRX6hDjHwFoT7i3w== X-Received: by 2002:a17:902:be0e:: with SMTP id r14-v6mr11498583pls.158.1525826564784; Tue, 08 May 2018 17:42:44 -0700 (PDT) From: Kees Cook To: Matthew Wilcox Cc: Kees Cook , Rasmus Villemoes , linux-kernel@vger.kernel.org, linux-mm@kvack.org, kernel-hardening@lists.openwall.com Subject: [PATCH 05/13] mm: Use array_size() helpers for kvmalloc() Date: Tue, 8 May 2018 17:42:21 -0700 Message-Id: <20180509004229.36341-6-keescook@chromium.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180509004229.36341-1-keescook@chromium.org> References: <20180509004229.36341-1-keescook@chromium.org> X-Virus-Scanned: ClamAV using ClamSMTP Instead of open-coded multiplication, use the new array_size() helper to detect overflow in kvmalloc()-family functions. Signed-off-by: Kees Cook --- include/linux/mm.h | 6 +++--- include/linux/vmalloc.h | 1 + 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/include/linux/mm.h b/include/linux/mm.h index 1ac1f06a4be6..c97ed9aa3412 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -25,6 +25,7 @@ #include #include #include +#include struct mempolicy; struct anon_vma; @@ -560,10 +561,9 @@ static inline void *kvzalloc(size_t size, gfp_t flags) static inline void *kvmalloc_array(size_t n, size_t size, gfp_t flags) { - if (size != 0 && n > SIZE_MAX / size) - return NULL; + size_t bytes = array_size(n, size); - return kvmalloc(n * size, flags); + return kvmalloc(bytes, flags); } extern void kvfree(const void *addr); diff --git a/include/linux/vmalloc.h b/include/linux/vmalloc.h index 1e5d8c392f15..398e9c95cd61 100644 --- a/include/linux/vmalloc.h +++ b/include/linux/vmalloc.h @@ -8,6 +8,7 @@ #include #include /* pgprot_t */ #include +#include struct vm_area_struct; /* vma defining user mapping in mm_types.h */ struct notifier_block; /* in notifier.h */