From patchwork Wed May 9 20:02:22 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kees Cook X-Patchwork-Id: 10390781 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 2618860353 for ; Wed, 9 May 2018 20:03:47 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 182E225EF7 for ; Wed, 9 May 2018 20:03:47 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0C6AC2852E; Wed, 9 May 2018 20:03:47 +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 401672853A for ; Wed, 9 May 2018 20:03:46 +0000 (UTC) Received: (qmail 26118 invoked by uid 550); 9 May 2018 20:02:58 -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 25970 invoked from network); 9 May 2018 20:02:51 -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=/JUjYk2nCovIupNyFgtiO+nuZfsAJgLxrIErm5uq/jE=; b=mJ7xuHiq9S98O48lqDPJDCagDsrvlpP7qx6SEl1r/7ORLcnUcdKZCACTUH20WhH9ZM 1NFvywKDpfkrKL8lFpy+jhCziZEXVkdCt+eo+DCl+1pgKo6pQVd6QX6bjTXkuvQVlSxT 00SPlkE97HJYhywAu43Yi8iaHmhZZu9qMfhus= 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=/JUjYk2nCovIupNyFgtiO+nuZfsAJgLxrIErm5uq/jE=; b=NB5MRpxKN6LMFm28ChtnuGDQ2JChP1Ns/lHOJvHBw0bWUigu5swkji0Kq3t8ANCwQj odIXJrNsV5SM8MwYDYGZCkgUpYRt0x0BoINkc/D2MqELXVBocsxG9cqvkhGnfSvbkGsn xMFTBac2h9Np1mHe+9Wx5lQcJ61hSQRr5XHm++bzq7fffvAUn5JidnueJbl6Ki8+ULP7 TwPAhso3b9xlEnofx8ckgo7oRsopiHWZKYcrUbaofuvTB6DZXPnpuGWTM9JKN+8x06Nz f4AAXhcrZFSLuKVMTFlhr+3qHvqER06tQQA2tXISQd/lVL7sk65oBxDsOlQANix0BlPR 5JQw== X-Gm-Message-State: ALQs6tDRbi2iHc3V6pfFBLf1R3f6J7iSzqkl4oEP9ft0GJ4pH+mUqwW3 aB57h8nVbwx/2BfPxQxcTi8jkw== X-Google-Smtp-Source: AB8JxZpkQqIb9eJY14jlKD49wRZJ4IJ0EoyY/Sia3/Cmp3rWRTUWRz3M1DXkqe+eXuD3SAhJE2fMhQ== X-Received: by 10.98.67.83 with SMTP id q80mr45159809pfa.228.1525896160090; Wed, 09 May 2018 13:02:40 -0700 (PDT) From: Kees Cook To: Matthew Wilcox Cc: Kees Cook , Rasmus Villemoes , Matthew Wilcox , LKML , Linux-MM , Kernel Hardening Subject: [PATCH v2 5/6] mm: Use overflow helpers in kvmalloc() Date: Wed, 9 May 2018 13:02:22 -0700 Message-Id: <20180509200223.22451-6-keescook@chromium.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180509200223.22451-1-keescook@chromium.org> References: <20180509200223.22451-1-keescook@chromium.org> X-Virus-Scanned: ClamAV using ClamSMTP Instead of open-coded multiplication and bounds checking, use the new overflow helper. Additionally prepare for vmalloc() users to add array_size()-family helpers in the future. Signed-off-by: Kees Cook --- include/linux/mm.h | 7 +++++-- include/linux/vmalloc.h | 1 + 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/include/linux/mm.h b/include/linux/mm.h index 1ac1f06a4be6..7cb1c6a6bf82 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,12 @@ 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) + size_t bytes; + + if (unlikely(check_mul_overflow(n, size, &bytes))) return NULL; - 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 */