Received: by 2002:a25:d7c1:0:0:0:0:0 with SMTP id o184csp2486624ybg; Thu, 24 Oct 2019 10:24:04 -0700 (PDT) X-Google-Smtp-Source: APXvYqwBhghW3RxYJUk8yVVW7KdX7RDF1NGV80jalSuvEpeYOhtzBopWE34MN6UyK4axHmyZPUeQ X-Received: by 2002:a50:8871:: with SMTP id c46mr26290149edc.24.1571937844016; Thu, 24 Oct 2019 10:24:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1571937844; cv=none; d=google.com; s=arc-20160816; b=ttaztHEFI/CdTcrI79VefoKiQvq/tDSIVsF8UCGDooZhu7FN+a0nGU0m0ttMrSi+3A 5dYblAEbb7mO0zjlvM4oNlYTIepk9OC3QX9kWa3hBSM7H9tyuu0p9lKVqCD7/oxg9nsr 02G/FBFRGn1UAqtQbB0h3waaL6jsoijVn71aLeB6Oekii0Uk988W/Iek7MgCLak1K6gg JITmFAdMwB4EHOgoXXLPWv83uZGN0O6DPkMunHl+l4aPc7Uia6xD5DiNX7zwlrrJvymZ SYOI8TjMgTNSsAVebVGgQ4ydtoxSDnri6Wx/7I4N/ivWUAA8z3Yaj8DMKsksGzBkSk4B n5jQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=LUXGEETBvCcBLZu+5N1PADlLxqK4jppDWqJHP95xhoM=; b=Zn+Q0R7GZoQgE8gfZtKGEjZ13n4HBvBgq96IjwkRnx+4ObYbyaQiGNHHyETAkxDZke qUcq9mMOfoC30S3A9z2L/3ynnyqJh3VetaMIJ0Em+gOiSs/Z6AfaQDe+leK0OoNj/mhc RuBtPLOaTLmHs9dEot6dBqYvNIh9jmcIrRZ9HvsddCD2FIgBrmqzOa96dHqKFXXrDMVe UbDF0pjIQUZpOJah1XI1/i2H+eIvBO5yRzEfFrPJQNnO8IBz0yGk5Zf9l1kDheMk1WM9 PqOxrkGnJE/6QRrVyd6mq6LyiGQR/bQ9XnonurpDpK4oxLX5kAjDnrXf97nUCF/1Foi7 lZkg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=hgo1tTqy; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 11si13078992edv.422.2019.10.24.10.23.39; Thu, 24 Oct 2019 10:24:04 -0700 (PDT) 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=@google.com header.s=20161025 header.b=hgo1tTqy; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2408098AbfJXAmb (ORCPT + 99 others); Wed, 23 Oct 2019 20:42:31 -0400 Received: from mail-pg1-f196.google.com ([209.85.215.196]:34343 "EHLO mail-pg1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2408092AbfJXAmb (ORCPT ); Wed, 23 Oct 2019 20:42:31 -0400 Received: by mail-pg1-f196.google.com with SMTP id k20so13148686pgi.1 for ; Wed, 23 Oct 2019 17:42:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=LUXGEETBvCcBLZu+5N1PADlLxqK4jppDWqJHP95xhoM=; b=hgo1tTqyRFfyzQv2OcL/tBjhnyeaQkOXCW1UdFe54sVVt5yCbNBd2/b4dA+vHazekb zDu3uTT2j/++aRlvyk5c2Zm8C1nybWUVOHVDllkDsMyNhNSIpdo2aF3WTz33RtrFer3I pnh6GFpGx2LdS2hXJo/Wcm06srTtUZodnYmvTqp+2b0CV/xMEu5QtJnpEHsY7SkSCZah yPbwwyIiuPEsvqgV8mKW+3pv7EssjoDq1val32jBsYbkQ6gfiYLdCVWMqp9GoOmST5hB Mej6locdjzzG0iS/6EXDCZrQ7DPIVwKc6/QDKzVKdz8K57eAhQJesOJY/CvT7YG8GMdG kTFw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=LUXGEETBvCcBLZu+5N1PADlLxqK4jppDWqJHP95xhoM=; b=Oop2FnkqiEGsRnqCD7jwZP9rtKQjEt2ZdmahKxMtcohTIPVm/tgGQEtBMnBq7PO6s2 LEgWzMIOII4ljp55Jl9LZZFNgfRSrfeUecEAZHqWXVucyBrY2/yLjxvaP9s3qnzRnzbk ZDtOuDjlS+WfaiPETe632tzbjPE9sVOmtYtgIZN3CDWfvvVTSxXq4wOWVTs+2jBHZqPk mQRH3D7z2akYBbUxF4Td9Bml0InRWTACeEWCqQJkYCZMbHJIbpznlFQECeIANVuFDNnJ B1aQEtV4lCZjIhVg+MbyLFbJnuY76cafo40FYB7Sxm8foJYdrGdgWfGmvp2qAsePIlHy gcIA== X-Gm-Message-State: APjAAAWu7BmTNsp/94mAVSRdQB/pbq7p5UX9ziUbOqEpwmnIdVAeY90m xX3dPe5RWF9+4KNRSGK+018bWkPE3mdGuydf0y2kKw== X-Received: by 2002:a63:3044:: with SMTP id w65mr12961228pgw.384.1571877749882; Wed, 23 Oct 2019 17:42:29 -0700 (PDT) MIME-Version: 1.0 References: <20191018001816.94460-1-brendanhiggins@google.com> <20191018122949.GD11244@42.do-not-panic.com> In-Reply-To: From: Brendan Higgins Date: Wed, 23 Oct 2019 17:42:18 -0700 Message-ID: Subject: Re: [PATCH linux-kselftest/test v1] apparmor: add AppArmor KUnit tests for policy unpack To: Alan Maguire Cc: Luis Chamberlain , Matthias Maennich , shuah , John Johansen , jmorris@namei.org, serge@hallyn.com, Kees Cook , Iurii Zaikin , David Gow , "Theodore Ts'o" , Linux Kernel Mailing List , linux-security-module@vger.kernel.org, KUnit Development , "open list:KERNEL SELFTEST FRAMEWORK" , Mike Salvatore Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sat, Oct 19, 2019 at 5:56 AM Alan Maguire wrote: > > On Fri, 18 Oct 2019, Luis Chamberlain wrote: > > > On Thu, Oct 17, 2019 at 05:18:16PM -0700, Brendan Higgins wrote: > > > From: Mike Salvatore > > > > > > 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. > > > > And you'd run into the same situation expressed elsewhere with kunit of > > an issue of the kunit test as built-in working but if built as a module > > then it would not work, given the lack of exports. Symbols namespaces > > should resolve this [0], and we'd be careful where a driver imports this > > namespace. > > > > [0] https://lwn.net/Articles/798254/ Maybe I am not understanding how the symbol namespaces work, but it seems that it doesn't actually solve our problem, at least not all of it. First off this doesn't solve the problem for when a piece of code is included as a module; it also does not address the problem for symbols that would not normally be exported. Also, I think we still expect a symbol that is not static to have an appropriate prefix, right? As in, it is *not* okay to have a non-static symbol in apparmor called "inbounds", correct? > WRT adding tests, I think what we're aiming at is a set of best practices > to advise test developers using KUnit, while attempting to minimize > side-effects of any changes we need to make to support testability. > > One aspect of this we probably have to consider is inlining of code. For > cases like this where the functions are small and are called in a small > number of cases, any testability changes we make may push a > previously-inlined function to not be inlined, with potential performance > side-effects for the subsystem. In such cases, I wonder if the right > answer would be to suggest actually defining the functions as > inline in the header file? That way the compiler still gets to decide (as > opposed to __always_inline), and we don't perturb performance too much. That's a really good point. Okay, so it seems that making the symbols public when not testing is probably not okay on its own. If we are going to do that, we probably need to do something like what you are suggesting. With that, I think the best solution in this case will be the "__visible_for_testing" route. It has no overhead when testing is turned off (in fact it is no different in anyway when testing is turned off). The downsides I see are: 1) You may not be able to test non-module code not compiled for testing later with the test modules that Alan is working on (But the only way I think that will work is by preventing the symbol from being inlined, right?). 2) I think "__visible_for_testing" will be prone to abuse. Here, I think there are reasons why we might want to expose these symbols for testing, but not otherwise. Nevertheless, I think most symbols that should be tested should probably be made visible by default. Since you usually only want to test your public interfaces. I could very well see this getting used as a kludge that gets used far too frequently. Nevertheless, based on Alan's point, I suspect it, for this case at least, will likely be the least painful. How do people feel about that?