From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id DDEE1C433FE for ; Tue, 8 Mar 2022 22:12:57 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 39F5A8D0002; Tue, 8 Mar 2022 17:12:57 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 3270C8D0001; Tue, 8 Mar 2022 17:12:57 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1C7B48D0002; Tue, 8 Mar 2022 17:12:57 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (relay.a.hostedemail.com [64.99.140.24]) by kanga.kvack.org (Postfix) with ESMTP id 0A10D8D0001 for ; Tue, 8 Mar 2022 17:12:57 -0500 (EST) Received: from smtpin12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay11.hostedemail.com (Postfix) with ESMTP id C0B3E80879 for ; Tue, 8 Mar 2022 22:12:56 +0000 (UTC) X-FDA: 79222619952.12.E10C8D8 Received: from mail-pg1-f179.google.com (mail-pg1-f179.google.com [209.85.215.179]) by imf19.hostedemail.com (Postfix) with ESMTP id 4CCE11A000D for ; Tue, 8 Mar 2022 22:12:56 +0000 (UTC) Received: by mail-pg1-f179.google.com with SMTP id 6so369741pgg.0 for ; Tue, 08 Mar 2022 14:12:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=bkKtesSrq7QqPtPRsrv5MP5UVhIFuJzVkEWr+6F4jZg=; b=HB7Qh4AtVpk8d37bKeerp0qFPsowgSyoNUGO3LpWmMZyfhC0KY2vF+/9yFB3whMWqV r6ygdwoC5f3KyA6nBZBdysI+OaD0+1ZMeKlMNQMyoVYqJrw7jHy0RmxmooM5aq4XJh/k 7px/K05dn+P2MGUsxJHuEwW0DQyufasrdA/CY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=bkKtesSrq7QqPtPRsrv5MP5UVhIFuJzVkEWr+6F4jZg=; b=weDQQ2pgE2MD7mGlaLJINKKNx5Nf5se1dSyJn8/EKHSlrd0fV7EuQP5au21hQ8uxOB kSBLylfHKZCvlqqdtPhcYOJcGR01i0ggVFKG5V03/HwcvvYLLDI5h7+L4MYxbYUPrE/I hP1OvEETrV6jyXR2N2LA2G4sPAGTCnMbKNlqiXZs9VpdthF5OVDfGZIHwQdIqIPdeF0S 8PMsLTsMcmbIEb8ZMZLs3jQqlfIE6xGZ1pIdYL4GFq5OtqLyedhIHyST9MHLKF3xMVJe znarJUu6u26tUWOteKcUHndfN38jlr2K+xOG8Jxck/BaXVHwHxqY1rnEcsWeovp4Nh4X kqbg== X-Gm-Message-State: AOAM5319CO7xUqON923/NGl00Zq5kXyqZ05/BqwKx03yutiXdyF75ex8 21RLArTK3E8BuJ+HSjkanK3OEQ== X-Google-Smtp-Source: ABdhPJxAagA58tSNDoUZKDWEzQaeBwAsi4rPzMdnA3AIz7iJkUTWHfbJDFjsTEW6XG4sdCX9pvm2qg== X-Received: by 2002:aa7:8256:0:b0:4e0:78ad:eb81 with SMTP id e22-20020aa78256000000b004e078adeb81mr20546718pfn.30.1646777575321; Tue, 08 Mar 2022 14:12:55 -0800 (PST) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id s9-20020a056a00194900b004e1583f88a2sm66527pfk.0.2022.03.08.14.12.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Mar 2022 14:12:55 -0800 (PST) Date: Tue, 8 Mar 2022 14:12:54 -0800 From: Kees Cook To: Alexey Dobriyan Cc: David Gow , Eric Biederman , Daniel Latypov , Magnus =?iso-8859-1?Q?Gro=DF?= , Alexander Viro , linux-kernel@vger.kernel.org, kunit-dev@googlegroups.com, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-hardening@vger.kernel.org Subject: Re: [PATCH v2] binfmt_elf: Introduce KUnit test Message-ID: <202203081408.0B0FC34C@keescook> References: <20220304044831.962450-1-keescook@chromium.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Rspamd-Queue-Id: 4CCE11A000D X-Stat-Signature: iy7c18zqgafs3qzyqg6mazhrbak7xmxx Authentication-Results: imf19.hostedemail.com; dkim=pass header.d=chromium.org header.s=google header.b=HB7Qh4At; spf=pass (imf19.hostedemail.com: domain of keescook@chromium.org designates 209.85.215.179 as permitted sender) smtp.mailfrom=keescook@chromium.org; dmarc=pass (policy=none) header.from=chromium.org X-Rspam-User: X-Rspamd-Server: rspam08 X-HE-Tag: 1646777576-205256 X-Bogosity: Ham, tests=bogofilter, spamicity=0.019242, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Wed, Mar 09, 2022 at 12:24:56AM +0300, Alexey Dobriyan wrote: > On Thu, Mar 03, 2022 at 08:48:31PM -0800, Kees Cook wrote: > > Adds simple KUnit test for some binfmt_elf internals: specifically a > > regression test for the problem fixed by commit 8904d9cd90ee ("ELF: > > fix overflow in total mapping size calculation"). > > > + /* No headers, no size. */ > > + KUNIT_EXPECT_EQ(test, total_mapping_size(NULL, 0), 0); > > This is meaningless test. This whole function only makes sense > if program headers are read and loading process advances far enough > so that pointer is not NULL. I think it's important to start adding incremental unit testing to core kernel APIs. This is a case of adding a regression test for a specific misbehavior. This is good, but in addition, testing should check any other corner cases as well. Yes, the above EXPECT line is total nonsense, and it makes sure that nonsense actually reports back the expected failure state "0". > Are we going to mock every single function in the kernel? > Disgusting. I'm not really interested in a slippery slope debate, but honestly, if we _could_ mock everything in the kernel and create unit tests for everything in the kernel, then yes, we should. It's certainly not feasible, but at least _getting started_ on unit testing execve is worth it. -- Kees Cook