From patchwork Fri Jun 1 00:42:20 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kees Cook X-Patchwork-Id: 10442199 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 B3484602BC for ; Fri, 1 Jun 2018 00:43:48 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AD3F428E43 for ; Fri, 1 Jun 2018 00:43:48 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A206428E58; Fri, 1 Jun 2018 00:43:48 +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=-3.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 22E8828E43 for ; Fri, 1 Jun 2018 00:43:48 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 119AB6B0008; Thu, 31 May 2018 20:43:45 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 0B1A86B000D; Thu, 31 May 2018 20:43:44 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E20506B000E; Thu, 31 May 2018 20:43:44 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pl0-f69.google.com (mail-pl0-f69.google.com [209.85.160.69]) by kanga.kvack.org (Postfix) with ESMTP id A30CA6B000A for ; Thu, 31 May 2018 20:43:44 -0400 (EDT) Received: by mail-pl0-f69.google.com with SMTP id x2-v6so14274837plv.0 for ; Thu, 31 May 2018 17:43:44 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:dkim-signature:from:to:cc:subject:date :message-id:in-reply-to:references; bh=CQ8LksIQh9KsZ1H2uceEEDPecstNN01yGfGOCPPwwSo=; b=KiZ+X3G/l/Vbddje7DFq8nAI8cI4y0brDpC5v5c5E9o+oo/DfbpbM3LzKWChHH1eXh Jn7ZSqT6gszjtMWmgpKLrm/YomUIcvd/dKQ77DHrr797ptEcKpMCpJ3JH9YqXC2lpImt WTtJB0suV2UVTfBwKX18QgfTVrL7hwW2NwWx1HVnwAl4HjDrE17xDya8i/ek0IRw5I/d 69MWYo/DNYrhUOdYgkuw1fOjV7+Ux1WolURZDoSq8k2zoDfhDH3/4Kgd286EAWjoQSnp 76l4NdprhqTwdLh7G3Wj3psNcP85BecN/2RpSNLeUwyWhBv+kvWDingdmFwwrUAClZRG JKFA== X-Gm-Message-State: ALKqPwfQlqR1ODmytwqW0TYsy0GnT6NaFUZRJGsv4Dor+htOgYAnpgf1 PmOfzsKDy4akcKxsmYeP7sD6CXnt3vtu4FRjxGMeLPv8mz3CC05YLd7x904MOjbb7nY92gxSGE5 yce9rFuHBqqlLnZCn67WHmNn8K83hUWXWfDcmNpPfAI3WWLBbks3t7rCBocQLtlGwdBHRIf/U8i O/sK85n4eE2NATpeJxSh1BzT3XopytkMvfxUX/+aP3NbQWE0m9MSb8DSy6TsMy3bXQh5O3+vpPL p2imIrJ6V+0yxTJFIPoMT0d2pcYDpinlq/+WF8Ay0palZJ/8aClVOku6I3TW+Ck8gfdE+8x7IkH Lvnr7pRCm7UY7HMZHb3ReQItScsfPt0OjC8d63g6WPPwBZJo2bWT4n1hKwH5Kcowgr+6XD6CRya 3 X-Received: by 2002:a62:18a:: with SMTP id 132-v6mr8763205pfb.62.1527813824343; Thu, 31 May 2018 17:43:44 -0700 (PDT) X-Received: by 2002:a62:18a:: with SMTP id 132-v6mr8763175pfb.62.1527813823461; Thu, 31 May 2018 17:43:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527813823; cv=none; d=google.com; s=arc-20160816; b=FA/o+r0YByidYz4NekZqcD62aXyw1gqXgEVKXwxuEQJIzmlDOPKyqS0hN0RXl04h3Q i2K1JsyA4DzwCSMGNpbrJwjxn/n+IfVFYNd/AQ8GKBuAF4h5geAa5TAxT//nkNcSfDwJ sjMVIZ/p82OjFqPNmZYjXcshtbvonWFSd7oQSo05ndCqKrGygfZSkmD2E7Yp5tYyWYQG 1oSBZuFdL2cewdKclPuC2CHNkswf/NVOKJiRdJPihJE4iI80S7R9nmBJxG6zRMzPYRlk C4BIatZMiYeoPod1Ek/n/+0/PJnPDrXfdadECrhJmUIe4wmefWFuIc0jdfi/kk5uYE3x jRbg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature:arc-authentication-results; bh=CQ8LksIQh9KsZ1H2uceEEDPecstNN01yGfGOCPPwwSo=; b=CxuoDIxjhw4sMp33vi5QNhnYFJVwkGN4ZfxbKtjnUUYbgpxzaGTVLHUEQfPNHmWyvY hr2V+CQT9ykrXG9psZWOcDcn3SVuO2H6pv1yycfhPIv66eluyeCOojO69cx72yqZL5Nm Jvk9Sd2Cb5gQR/QxZjZOpPkdjgOiKYZmLHYOPPkq/gphUEMVXZM8X1KwQrnljaLyqzcb NcxLBOgfRJ3CbX5ZhDFcwnvykwGa2hEI1IQVOD39BPBsbejGwwb42kWe1xh9o+8jnZGG pVeQzA77vfCOJOl0eM4IoK75pf7FPdx4D4gI7+erjS3sc1CfikcX/UVJquhblWpQ0T5w cVBw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=X2Rrbx+J; spf=pass (google.com: domain of keescook@chromium.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=keescook@chromium.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id i3-v6sor16555214pld.65.2018.05.31.17.43.43 for (Google Transport Security); Thu, 31 May 2018 17:43:43 -0700 (PDT) Received-SPF: pass (google.com: domain of keescook@chromium.org designates 209.85.220.65 as permitted sender) client-ip=209.85.220.65; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=X2Rrbx+J; spf=pass (google.com: domain of keescook@chromium.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=keescook@chromium.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org 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=CQ8LksIQh9KsZ1H2uceEEDPecstNN01yGfGOCPPwwSo=; b=X2Rrbx+JqI3CdJeiQi/z+NhzfXvz07/PR8IOTT2AMqEMCe/SN/9z05iz6DPK0Lmq6g uQ7szkQztiaj/3Ne3d7YqzHJ1u8om4LZ+MyaCOtsLGfUkk2KtwzGUuYaxtOctQP8FDfp rMo+2+X3UFYvt4RN78mDJy3Hl/Wc3CXZNF4hw= X-Google-Smtp-Source: ADUXVKLJf68l0gHanyLEhr7CAR1CYwoE5tW4NkFgzIvFdrqHGrrskT5GOR20XOemwAS8yZrhuamc+w== X-Received: by 2002:a17:902:3124:: with SMTP id w33-v6mr4471859plb.235.1527813823197; Thu, 31 May 2018 17:43:43 -0700 (PDT) Received: from www.outflux.net (173-164-112-133-Oregon.hfc.comcastbusiness.net. [173.164.112.133]) by smtp.gmail.com with ESMTPSA id g15-v6sm49160300pgv.58.2018.05.31.17.43.40 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 31 May 2018 17:43:41 -0700 (PDT) From: Kees Cook To: Matthew Wilcox Cc: Kees Cook , Linus Torvalds , Rasmus Villemoes , Matthew Wilcox , LKML , Linux-MM , Kernel Hardening Subject: [PATCH v3 03/16] lib: overflow: Report test failures Date: Thu, 31 May 2018 17:42:20 -0700 Message-Id: <20180601004233.37822-4-keescook@chromium.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180601004233.37822-1-keescook@chromium.org> References: <20180601004233.37822-1-keescook@chromium.org> X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP This adjusts the overflow test to report failures, and prepares to add allocation tests. Signed-off-by: Kees Cook --- lib/test_overflow.c | 75 ++++++++++++++++++++++++++++++++------------- 1 file changed, 54 insertions(+), 21 deletions(-) diff --git a/lib/test_overflow.c b/lib/test_overflow.c index e1e45ba17ff0..482d71c880fa 100644 --- a/lib/test_overflow.c +++ b/lib/test_overflow.c @@ -212,42 +212,59 @@ DEFINE_TEST_ARRAY(s64) = { }; #define DEFINE_TEST_FUNC(t, fmt) \ -static void __init do_test_ ## t(const struct test_ ## t *p) \ +static int __init do_test_ ## t(const struct test_ ## t *p) \ { \ t r; \ + int err = 0; \ bool of; \ \ of = check_add_overflow(p->a, p->b, &r); \ - if (of != p->s_of) \ + if (of != p->s_of) { \ pr_warn("expected "fmt" + "fmt" to%s overflow (type %s)\n", \ p->a, p->b, p->s_of ? "" : " not", #t); \ - if (r != p->sum) \ + err = 1; \ + } \ + if (r != p->sum) { \ pr_warn("expected "fmt" + "fmt" == "fmt", got "fmt" (type %s)\n", \ p->a, p->b, p->sum, r, #t); \ + err = 1; \ + } \ \ of = check_sub_overflow(p->a, p->b, &r); \ - if (of != p->d_of) \ + if (of != p->d_of) { \ pr_warn("expected "fmt" - "fmt" to%s overflow (type %s)\n", \ p->a, p->b, p->s_of ? "" : " not", #t); \ - if (r != p->diff) \ + err = 1; \ + } \ + if (r != p->diff) { \ pr_warn("expected "fmt" - "fmt" == "fmt", got "fmt" (type %s)\n", \ p->a, p->b, p->diff, r, #t); \ + err = 1; \ + } \ \ of = check_mul_overflow(p->a, p->b, &r); \ - if (of != p->p_of) \ + if (of != p->p_of) { \ pr_warn("expected "fmt" * "fmt" to%s overflow (type %s)\n", \ p->a, p->b, p->p_of ? "" : " not", #t); \ - if (r != p->prod) \ + err = 1; \ + } \ + if (r != p->prod) { \ pr_warn("expected "fmt" * "fmt" == "fmt", got "fmt" (type %s)\n", \ p->a, p->b, p->prod, r, #t); \ + err = 1; \ + } \ + \ + return err; \ } \ \ -static void __init test_ ## t ## _overflow(void) { \ +static int __init test_ ## t ## _overflow(void) { \ unsigned i; \ + int err = 0; \ \ pr_info("%-3s: %zu tests\n", #t, ARRAY_SIZE(t ## _tests)); \ for (i = 0; i < ARRAY_SIZE(t ## _tests); ++i) \ - do_test_ ## t(&t ## _tests[i]); \ + err |= do_test_ ## t(&t ## _tests[i]); \ + return err; \ } DEFINE_TEST_FUNC(u8, "%d"); @@ -260,26 +277,42 @@ DEFINE_TEST_FUNC(s16, "%d"); DEFINE_TEST_FUNC(s32, "%d"); DEFINE_TEST_FUNC(s64, "%lld"); -static int __init test_overflow(void) +static int __init test_overflow_calculation(void) +{ + int err = 0; + + err |= test_u8_overflow(); + err |= test_u16_overflow(); + err |= test_u32_overflow(); + err |= test_u64_overflow(); + + err |= test_s8_overflow(); + err |= test_s16_overflow(); + err |= test_s32_overflow(); + err |= test_s64_overflow(); + + return err; +} + +static int __init test_module_init(void) { - test_u8_overflow(); - test_u16_overflow(); - test_u32_overflow(); - test_u64_overflow(); + int err = 0; - test_s8_overflow(); - test_s16_overflow(); - test_s32_overflow(); - test_s64_overflow(); + err |= test_overflow_calculation(); - pr_info("done\n"); + if (err) { + pr_warn("FAIL!\n"); + err = -EINVAL; + } else { + pr_info("all tests passed\n"); + } - return 0; + return err; } static void __exit test_module_exit(void) { } -module_init(test_overflow); +module_init(test_module_init); module_exit(test_module_exit); MODULE_LICENSE("Dual MIT/GPL");