Received: by 2002:a25:31c3:0:0:0:0:0 with SMTP id x186csp850795ybx; Wed, 6 Nov 2019 09:19:50 -0800 (PST) X-Google-Smtp-Source: APXvYqw/eUZGINpL/C1jLE86UMgHO5xGJQiZIjEL83OFD8GmNOSD5317SvBzuqjcy8hKJDFik4oX X-Received: by 2002:a17:906:459:: with SMTP id e25mr40257eja.259.1573060790763; Wed, 06 Nov 2019 09:19:50 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1573060790; cv=none; d=google.com; s=arc-20160816; b=iH9++2Za+ncDtFQpiBCfWI6/nFljyv4jS6auNraoP1TyFPdugf0/hgs09MhkaTCDvn UvJvZrhlE0/m+obd/WBZD0MViy+AUujj4p+A5d8OXhaWXOJL+suM0EESCmGPbWLMeJSj 7m88AB7sFD+sKFuRc/Fi2U22CS9166aaoAgFM4NNDKj4QFuDrzNIb8Xz6xk5WpIfPqfr SLsmQZocP7ttXZSufyBKyay+ZxfxRa/wxyJMORbr2lFwv4M0cP4DxUqrecAsv8ihqeDb NX10BK7xm9EtdwEozVWCFdXdMJ0HWkXy1Gda4jx5V2Nf8lQvUIzahCJuzSngLzecm0XN AzWA== 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:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=kqep8XBz+ob9m9HgLeaELks6sa5oaorHLu84jPUpdI0=; b=ykICQKiGmBOHppzGYFN7jrXkKQR/1oKptFeTiA2vqGOPghdPP/BE/KK+6NF4xK/9xL xG+lXTe8Tt6CdqHrFFCiYozVcqxHilEcM2reVSXION3ztZVn5YR0taEqX2Bjuj6VKiTL xnT/ofdF2ARUWygUt3XqSL2ACHbHcLJRY3Oo56ZhQNBQOSVwXXOlcIat6mmP19BPF/9S TfbVXyd3rA9lX22bSz7PpWES+8LQBUbIrnvnyADYy8hIrKBY+vGuPouMiyT3IEEqnNXN H2gy9SYuGJpQ8V12gDMitS7yB8FPB4n41e9/o2AVtBpDCHtnLgPQGbqxS7BJdkd+/JB8 IbTw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=Tfm+AIKz; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f18si14032055ejf.210.2019.11.06.09.19.26; Wed, 06 Nov 2019 09:19:50 -0800 (PST) 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; dkim=pass header.i=@chromium.org header.s=google header.b=Tfm+AIKz; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732344AbfKFRSb (ORCPT + 99 others); Wed, 6 Nov 2019 12:18:31 -0500 Received: from mail-pg1-f194.google.com ([209.85.215.194]:40589 "EHLO mail-pg1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732329AbfKFRSa (ORCPT ); Wed, 6 Nov 2019 12:18:30 -0500 Received: by mail-pg1-f194.google.com with SMTP id 15so17577519pgt.7 for ; Wed, 06 Nov 2019 09:18:30 -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=kqep8XBz+ob9m9HgLeaELks6sa5oaorHLu84jPUpdI0=; b=Tfm+AIKzVLe4DKvn7S7UE7TTNFzSpLQpGOJ0dbBICYYiDkzHHhPep0L3G96Vp0HLkn 3iFEtU69J8jfFGl/vrroJ5cmlLPPZ/jEFJYPh5Iiuzsg9xZmv+vWYtIEUnvnADfAz+O0 6EHPI8OypMmHrVeVHx6LKUwBIdRVeHrA8kypc= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=kqep8XBz+ob9m9HgLeaELks6sa5oaorHLu84jPUpdI0=; b=pfqHQcfOUcIuMWpyW1GHTLW7igqlNGj7koFaGbmABVR3r3z07Sq3SZJIWANH6BBefF diVrdqZnalWzwRNMsFMrCgphaSBNTO8Ogih2t0TqjoRLIZCboGJY35ec+NZVT5LmVx7X SCaYeYR8tigNFPKALYh3z7+x2EYnJAAqxVW84h6uwuJn7b1IcHNH75VFS3STzIO09TGI iw3a8qY+DsXZ+9Umbfk479bG7N1i7UcyUrIyjQVu6foF4BX8kHn0MxOaXCEL8xy/tvGH 61zxTNPQXDvOT4HbxqmXT/6J5XwA7RAIo5LEkxkQitkawD7orjFgHhRDIIoLAZN1MQzI 7rdA== X-Gm-Message-State: APjAAAUvPC5vElIpaQ2dCWO0E7lpP4+KosAbEtVJRrVJXb1Z6PQmgifJ PwastVcX2Bt+8HenoZrMgFJyZA== X-Received: by 2002:a63:d452:: with SMTP id i18mr4222869pgj.76.1573060709773; Wed, 06 Nov 2019 09:18:29 -0800 (PST) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id s5sm3084844pjn.24.2019.11.06.09.18.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Nov 2019 09:18:28 -0800 (PST) Date: Wed, 6 Nov 2019 09:18:27 -0800 From: Kees Cook To: Brendan Higgins Cc: shuah@kernel.org, john.johansen@canonical.com, jmorris@namei.org, serge@hallyn.com, alan.maguire@oracle.com, yzaikin@google.com, davidgow@google.com, mcgrof@kernel.org, tytso@mit.edu, linux-kernel@vger.kernel.org, linux-security-module@vger.kernel.org, kunit-dev@googlegroups.com, linux-kselftest@vger.kernel.org, Mike Salvatore Subject: Re: [PATCH linux-kselftest/test v2] apparmor: add AppArmor KUnit tests for policy unpack Message-ID: <201911060916.AC9E14B@keescook> References: <20191106004329.16991-1-brendanhiggins@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20191106004329.16991-1-brendanhiggins@google.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Nov 05, 2019 at 04:43:29PM -0800, Brendan Higgins wrote: > From: Mike Salvatore > > Add KUnit tests to test AppArmor unpacking of userspace policies. > AppArmor uses a serialized binary format for loading policies. To find > policy format documentation see > Documentation/admin-guide/LSM/apparmor.rst. > > In order to write the tests against the policy unpacking code, some > static functions needed to be exposed for testing purposes. One of the > goals of this patch is to establish a pattern for which testing these > kinds of functions should be done in the future. > > Signed-off-by: Brendan Higgins > Signed-off-by: Mike Salvatore > --- > security/apparmor/Kconfig | 16 + > security/apparmor/policy_unpack.c | 4 + > security/apparmor/policy_unpack_test.c | 607 +++++++++++++++++++++++++ > 3 files changed, 627 insertions(+) > create mode 100644 security/apparmor/policy_unpack_test.c > > diff --git a/security/apparmor/Kconfig b/security/apparmor/Kconfig > index d8b1a360a6368..78a33ccac2574 100644 > --- a/security/apparmor/Kconfig > +++ b/security/apparmor/Kconfig > @@ -66,3 +66,19 @@ config SECURITY_APPARMOR_DEBUG_MESSAGES > Set the default value of the apparmor.debug kernel parameter. > When enabled, various debug messages will be logged to > the kernel message buffer. > + > +config SECURITY_APPARMOR_KUNIT_TEST > + bool "Build KUnit tests for policy_unpack.c" > + depends on KUNIT && SECURITY_APPARMOR > + help > + This builds the AppArmor KUnit tests. > + > + KUnit tests run during boot and output the results to the debug log > + in TAP format (http://testanything.org/). Only useful for kernel devs > + running KUnit test harness and are not for inclusion into a > + production build. > + > + For more information on KUnit and unit tests in general please refer > + to the KUnit documentation in Documentation/dev-tools/kunit/. > + > + If unsure, say N. > diff --git a/security/apparmor/policy_unpack.c b/security/apparmor/policy_unpack.c > index 8cfc9493eefc7..37c1dd3178fc0 100644 > --- a/security/apparmor/policy_unpack.c > +++ b/security/apparmor/policy_unpack.c > @@ -1120,3 +1120,7 @@ int aa_unpack(struct aa_loaddata *udata, struct list_head *lh, > > return error; > } > + > +#ifdef CONFIG_SECURITY_APPARMOR_KUNIT_TEST > +#include "policy_unpack_test.c" > +#endif /* CONFIG_SECURITY_APPARMOR_KUNIT_TEST */ To make this even LESS intrusive, the ifdefs could live in ..._test.c. Also, while I *think* the kernel build system will correctly track this dependency, can you double-check that changes to ..._test.c correctly trigger a recompile of policy_unpack.c? -- Kees Cook