From nobody Thu Sep 18 11:26:07 2025 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 44F87C352A1 for ; Wed, 7 Dec 2022 01:41:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229912AbiLGBlI (ORCPT ); Tue, 6 Dec 2022 20:41:08 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53262 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229878AbiLGBlF (ORCPT ); Tue, 6 Dec 2022 20:41:05 -0500 Received: from mail-yb1-xb49.google.com (mail-yb1-xb49.google.com [IPv6:2607:f8b0:4864:20::b49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9BA6F326CE for ; Tue, 6 Dec 2022 17:41:04 -0800 (PST) Received: by mail-yb1-xb49.google.com with SMTP id b4-20020a253404000000b006fad1bb09f4so17378647yba.1 for ; Tue, 06 Dec 2022 17:41:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=f2Av2mFA0WtwRQfRDDp1AcFtZ65WBT5TfOYBGjpZc8U=; b=ZSeF6gIU33eO2yCx/RBxl96g1hXO/NUYpPapQeVcTwE4Vg0/fBOlVSrYS97e5ecEHO XNPpGZncy+/Gh7h+b4LSvjIumlhokHRE09Pwo7LwQKIekr8yixl8QCQ0KIukFe02w2wT comOtXMfhFDFAUoy5ivekITX41zI6WVG8czk1z8lYcycv6IVhBJdmK46mlZx35jcXgGF 52pVZ8bzYLziNsMyUyQuMCEgz7XPjBlw0nbxY2WuQhHIoAgQn08onIVu02uiAZ094hGO rj7k4ucJcfb9tH6AEsJFJuADrgzDJeFRHEC1Ct11VgyQJ5N4T7/YnDQOTYD7sdUrRawe sCqQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=f2Av2mFA0WtwRQfRDDp1AcFtZ65WBT5TfOYBGjpZc8U=; b=FicpQ4lX+SwAf7iznuca2n/P74kGt0pgpYvZTFTBfw8EXPZc9valq5w+g9RwnxiWKf 4Wvciy9zTGnAxMEERTtKCOASfOxz5kX76eFTdsQibW1e4i1MwQTdbTjj1ZbBQLqrvUsW LKt6SsI8p4JExrZCTFurwvbPsJunViLXW1+T//Qn1rIj5YyhM/4MKF/AKAc0cEJpbgWj /j+WKoYigRvO0MjE4pYS57SWz3dr2nD1wz3gwNd1U8CYOQtQgrQ9XHalrDeHRhmdR05R os2JUANNxf4u6STDsjldJiRTmvrgziRYSTNVR0bAFZAtPCTWvJBkuLlykJW136Jpgx9q XSDg== X-Gm-Message-State: ANoB5pnD/wyjKWCj++Ril54f2DUlsbnnVFpdDl+JMSlfYrApmGnguQ4c r7HniIs0MdIM7hKlDq3oRVgD50Y50g== X-Google-Smtp-Source: AA0mqf75lqEvLvU57b4+1woivfdGDV7Rrauznoz21g86JMzcwRQz2dnJ6LFhFHKTp7RgXkDvBHH/e74eaQ== X-Received: from rmoar.c.googlers.com ([fda3:e722:ac3:cc00:2b:7d90:c0a8:4259]) (user=rmoar job=sendgmr) by 2002:a81:a1ce:0:b0:3bc:16af:8ded with SMTP id y197-20020a81a1ce000000b003bc16af8dedmr50465406ywg.176.1670377263945; Tue, 06 Dec 2022 17:41:03 -0800 (PST) Date: Wed, 7 Dec 2022 01:40:23 +0000 In-Reply-To: <20221207014024.340230-1-rmoar@google.com> Mime-Version: 1.0 References: <20221207014024.340230-1-rmoar@google.com> X-Mailer: git-send-email 2.39.0.rc0.267.gcb52ba06e7-goog Message-ID: <20221207014024.340230-2-rmoar@google.com> Subject: [PATCH v3 1/2] kunit: add macro to allow conditionally exposing static symbols to tests From: Rae Moar To: brendanhiggins@google.com, davidgow@google.com, dlatypov@google.com, john.johansen@canonical.com Cc: skhan@linuxfoundation.org, tales.aparecida@gmail.com, kunit-dev@googlegroups.com, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, apparmor@lists.ubuntu.com, Rae Moar Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Create two macros: VISIBLE_IF_KUNIT - A macro that sets symbols to be static if CONFIG_KUNIT is not enabled. Otherwise if CONFIG_KUNIT is enabled there is no change to the symbol definition. EXPORT_SYMBOL_IF_KUNIT(symbol) - Exports symbol into EXPORTED_FOR_KUNIT_TESTING namespace only if CONFIG_KUNIT is enabled. Must use MODULE_IMPORT_NS(EXPORTED_FOR_KUNIT_TESTING) in test file in order to use symbols. Signed-off-by: Rae Moar Reviewed-by: John Johansen Reviewed-by: David Gow --- Changes since v2: - No changes to this patch. Changes since v1: - Separated the documentation comments for macros. - Changed copyright date and author for new header file. include/kunit/visibility.h | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 include/kunit/visibility.h diff --git a/include/kunit/visibility.h b/include/kunit/visibility.h new file mode 100644 index 000000000000..0dfe35feeec6 --- /dev/null +++ b/include/kunit/visibility.h @@ -0,0 +1,33 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * KUnit API to allow symbols to be conditionally visible during KUnit + * testing + * + * Copyright (C) 2022, Google LLC. + * Author: Rae Moar + */ + +#ifndef _KUNIT_VISIBILITY_H +#define _KUNIT_VISIBILITY_H + +#if IS_ENABLED(CONFIG_KUNIT) + /** + * VISIBLE_IF_KUNIT - A macro that sets symbols to be static if + * CONFIG_KUNIT is not enabled. Otherwise if CONFIG_KUNIT is enabled + * there is no change to the symbol definition. + */ + #define VISIBLE_IF_KUNIT + /** + * EXPORT_SYMBOL_IF_KUNIT(symbol) - Exports symbol into + * EXPORTED_FOR_KUNIT_TESTING namespace only if CONFIG_KUNIT is + * enabled. Must use MODULE_IMPORT_NS(EXPORTED_FOR_KUNIT_TESTING) + * in test file in order to use symbols. + */ + #define EXPORT_SYMBOL_IF_KUNIT(symbol) EXPORT_SYMBOL_NS(symbol, \ + EXPORTED_FOR_KUNIT_TESTING) +#else + #define VISIBLE_IF_KUNIT static + #define EXPORT_SYMBOL_IF_KUNIT(symbol) +#endif + +#endif /* _KUNIT_VISIBILITY_H */ --=20 2.39.0.rc0.267.gcb52ba06e7-goog From nobody Thu Sep 18 11:26:07 2025 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id EA672C4708D for ; Wed, 7 Dec 2022 01:41:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229946AbiLGBlU (ORCPT ); Tue, 6 Dec 2022 20:41:20 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53376 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229879AbiLGBlL (ORCPT ); Tue, 6 Dec 2022 20:41:11 -0500 Received: from mail-yw1-x114a.google.com (mail-yw1-x114a.google.com [IPv6:2607:f8b0:4864:20::114a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4CCD552887 for ; Tue, 6 Dec 2022 17:41:08 -0800 (PST) Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-352e29ff8c2so175841197b3.21 for ; Tue, 06 Dec 2022 17:41:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=emH2PoLQAs0MJgn6nDhWA/n7PUBeBUvf8qNHIQw3Lvw=; b=JpbERIWVfKAwbrvEMOauy21Wfk8pswtIC/6WlV6UVUibHamspjYjeoagce5SrXJKFn 0bELJ/UyDJ/Wcn1htVwVkiHydxnxDezyr+qwgZ4EOr3h2wGXoKgmfDXrvR3y8ma1vNud nqSRfgsMz/B8lmuN8ztg+rfT3A2o1ALbyhVayypXMydUJCta7ECxO2elBA2Savm1s5qY w4ahMuoGe9bri8ojj7lOZwevPVULKyS9Obi31bpZBoVMCX2KoiccbHcGV/mhrS+qtHCB eFIjVNvKhkw8FL6IOuJOJaN7zrNz/8ALshdXciX4CjE2hP/tqHXPSNa2Mjt5cmRj+FKm QrIQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=emH2PoLQAs0MJgn6nDhWA/n7PUBeBUvf8qNHIQw3Lvw=; b=CTOvLVdhxSxUp5b5fmC0tGNcWSAcu5wo8MqIVg0qADQgR+KHx9RdbacA1e+vfy+qcV upm/7io4QdBaeZnP6DDr/e3WaSJ1AFUw1sWRRZYBdXXRI7xeNOmD7A9vF/x2Oh24/url y61kUTJtNvy2tF0LrksBrhemfx4Sr/B9zqIM+Zs4QqU/gX1557x3tGYRxu5Z06gw1ubw o/j+8beiJCJqTfy0P1278YqZXH89JYz6JOvIG3mrm3GEbAtY3kGB7pd6P1Pbz4Q2a4Rs nc3e2LAyDLNPrRpNWzvnuggBBGzMgheDFIApOkJ/MY4pHQFni3bKt7UjrgeYz+A8ZC9E BnkQ== X-Gm-Message-State: ANoB5pnXPU4W5hQU0UeOaqq1cFIHGm65kFjQYxmYKF0/0JNP40vf/Lt8 Puz1bIk9ky4a/b2vG/PrRSK+ghEzLw== X-Google-Smtp-Source: AA0mqf6HdVNeKzypoWJDGSnK570zPdc1UkSwgjncWqhuExIqdv/2R+EauH2pZnPyyLpHJ0fP2yTZol96oQ== X-Received: from rmoar.c.googlers.com ([fda3:e722:ac3:cc00:2b:7d90:c0a8:4259]) (user=rmoar job=sendgmr) by 2002:a0d:e8d0:0:b0:3f3:d22e:e14f with SMTP id r199-20020a0de8d0000000b003f3d22ee14fmr7115880ywe.85.1670377267624; Tue, 06 Dec 2022 17:41:07 -0800 (PST) Date: Wed, 7 Dec 2022 01:40:24 +0000 In-Reply-To: <20221207014024.340230-1-rmoar@google.com> Mime-Version: 1.0 References: <20221207014024.340230-1-rmoar@google.com> X-Mailer: git-send-email 2.39.0.rc0.267.gcb52ba06e7-goog Message-ID: <20221207014024.340230-3-rmoar@google.com> Subject: [PATCH v3 2/2] apparmor: test: make static symbols visible during kunit testing From: Rae Moar To: brendanhiggins@google.com, davidgow@google.com, dlatypov@google.com, john.johansen@canonical.com Cc: skhan@linuxfoundation.org, tales.aparecida@gmail.com, kunit-dev@googlegroups.com, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, apparmor@lists.ubuntu.com, Rae Moar Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Use macros, VISIBLE_IF_KUNIT and EXPORT_SYMBOL_IF_KUNIT, to allow static symbols to be conditionally set to be visible during apparmor_policy_unpack_test, which removes the need to include the testing file in the implementation file. Change the namespace of the symbols that are now conditionally visible (by adding the prefix aa_) to avoid confusion with symbols of the same name. Allow the test to be built as a module and namespace the module name from policy_unpack_test to apparmor_policy_unpack_test to improve clarity of the module name. Provide an example of how static symbols can be dealt with in testing. Signed-off-by: Rae Moar Reviewed-by: David Gow Acked-by: John Johansen --- Changes since v2: - Add mention of namespacing symbols to the commit message. - Change module name from policy_unpack_test to apparmor_policy_unpack_test. Changes since v1: - Changed the namespace of exported symbols for the apparmor policy_unpack_test by adding the aa_ prefix. security/apparmor/Kconfig | 4 +- security/apparmor/Makefile | 3 + security/apparmor/include/policy_unpack.h | 50 +++++ security/apparmor/policy_unpack.c | 238 ++++++++++------------ security/apparmor/policy_unpack_test.c | 69 ++++--- 5 files changed, 196 insertions(+), 168 deletions(-) diff --git a/security/apparmor/Kconfig b/security/apparmor/Kconfig index cb3496e00d8a..f334e7cccf2d 100644 --- a/security/apparmor/Kconfig +++ b/security/apparmor/Kconfig @@ -106,8 +106,8 @@ config SECURITY_APPARMOR_PARANOID_LOAD Disabling the check will speed up policy loads. =20 config SECURITY_APPARMOR_KUNIT_TEST - bool "Build KUnit tests for policy_unpack.c" if !KUNIT_ALL_TESTS - depends on KUNIT=3Dy && SECURITY_APPARMOR + tristate "Build KUnit tests for policy_unpack.c" if !KUNIT_ALL_TESTS + depends on KUNIT && SECURITY_APPARMOR default KUNIT_ALL_TESTS help This builds the AppArmor KUnit tests. diff --git a/security/apparmor/Makefile b/security/apparmor/Makefile index ff23fcfefe19..065f4e346553 100644 --- a/security/apparmor/Makefile +++ b/security/apparmor/Makefile @@ -8,6 +8,9 @@ apparmor-y :=3D apparmorfs.o audit.o capability.o task.o ip= c.o lib.o match.o \ resource.o secid.o file.o policy_ns.o label.o mount.o net.o apparmor-$(CONFIG_SECURITY_APPARMOR_HASH) +=3D crypto.o =20 +obj-$(CONFIG_SECURITY_APPARMOR_KUNIT_TEST) +=3D apparmor_policy_unpack_tes= t.o +apparmor_policy_unpack_test-objs +=3D policy_unpack_test.o + clean-files :=3D capability_names.h rlim_names.h net_names.h =20 # Build a lower case string table of address family names diff --git a/security/apparmor/include/policy_unpack.h b/security/apparmor/= include/policy_unpack.h index eb5f7d7f132b..e89b701447bc 100644 --- a/security/apparmor/include/policy_unpack.h +++ b/security/apparmor/include/policy_unpack.h @@ -48,6 +48,43 @@ enum { AAFS_LOADDATA_NDENTS /* count of entries */ }; =20 +/* + * The AppArmor interface treats data as a type byte followed by the + * actual data. The interface has the notion of a named entry + * which has a name (AA_NAME typecode followed by name string) followed by + * the entries typecode and data. Named types allow for optional + * elements and extensions to be added and tested for without breaking + * backwards compatibility. + */ + +enum aa_code { + AA_U8, + AA_U16, + AA_U32, + AA_U64, + AA_NAME, /* same as string except it is items name */ + AA_STRING, + AA_BLOB, + AA_STRUCT, + AA_STRUCTEND, + AA_LIST, + AA_LISTEND, + AA_ARRAY, + AA_ARRAYEND, +}; + +/* + * aa_ext is the read of the buffer containing the serialized profile. The + * data is copied into a kernel buffer in apparmorfs and then handed off to + * the unpack routines. + */ +struct aa_ext { + void *start; + void *end; + void *pos; /* pointer to current position in the buffer */ + u32 version; +}; + /* * struct aa_loaddata - buffer of policy raw_data set * @@ -126,4 +163,17 @@ static inline void aa_put_loaddata(struct aa_loaddata = *data) kref_put(&data->count, aa_loaddata_kref); } =20 +#if IS_ENABLED(CONFIG_KUNIT) +bool aa_inbounds(struct aa_ext *e, size_t size); +size_t aa_unpack_u16_chunk(struct aa_ext *e, char **chunk); +bool aa_unpack_X(struct aa_ext *e, enum aa_code code); +bool aa_unpack_nameX(struct aa_ext *e, enum aa_code code, const char *name= ); +bool aa_unpack_u32(struct aa_ext *e, u32 *data, const char *name); +bool aa_unpack_u64(struct aa_ext *e, u64 *data, const char *name); +size_t aa_unpack_array(struct aa_ext *e, const char *name); +size_t aa_unpack_blob(struct aa_ext *e, char **blob, const char *name); +int aa_unpack_str(struct aa_ext *e, const char **string, const char *name); +int aa_unpack_strdup(struct aa_ext *e, char **string, const char *name); +#endif + #endif /* __POLICY_INTERFACE_H */ diff --git a/security/apparmor/policy_unpack.c b/security/apparmor/policy_u= npack.c index 55d31bac4f35..12e535fdfa8b 100644 --- a/security/apparmor/policy_unpack.c +++ b/security/apparmor/policy_unpack.c @@ -14,6 +14,7 @@ */ =20 #include +#include #include #include #include @@ -37,43 +38,6 @@ #define v7 7 #define v8 8 /* full network masking */ =20 -/* - * The AppArmor interface treats data as a type byte followed by the - * actual data. The interface has the notion of a named entry - * which has a name (AA_NAME typecode followed by name string) followed by - * the entries typecode and data. Named types allow for optional - * elements and extensions to be added and tested for without breaking - * backwards compatibility. - */ - -enum aa_code { - AA_U8, - AA_U16, - AA_U32, - AA_U64, - AA_NAME, /* same as string except it is items name */ - AA_STRING, - AA_BLOB, - AA_STRUCT, - AA_STRUCTEND, - AA_LIST, - AA_LISTEND, - AA_ARRAY, - AA_ARRAYEND, -}; - -/* - * aa_ext is the read of the buffer containing the serialized profile. The - * data is copied into a kernel buffer in apparmorfs and then handed off to - * the unpack routines. - */ -struct aa_ext { - void *start; - void *end; - void *pos; /* pointer to current position in the buffer */ - u32 version; -}; - /* audit callback for unpack fields */ static void audit_cb(struct audit_buffer *ab, void *va) { @@ -199,10 +163,11 @@ struct aa_loaddata *aa_loaddata_alloc(size_t size) } =20 /* test if read will be in packed data bounds */ -static bool inbounds(struct aa_ext *e, size_t size) +VISIBLE_IF_KUNIT bool aa_inbounds(struct aa_ext *e, size_t size) { return (size <=3D e->end - e->pos); } +EXPORT_SYMBOL_IF_KUNIT(aa_inbounds); =20 static void *kvmemdup(const void *src, size_t len) { @@ -214,22 +179,22 @@ static void *kvmemdup(const void *src, size_t len) } =20 /** - * unpack_u16_chunk - test and do bounds checking for a u16 size based chu= nk + * aa_unpack_u16_chunk - test and do bounds checking for a u16 size based = chunk * @e: serialized data read head (NOT NULL) * @chunk: start address for chunk of data (NOT NULL) * * Returns: the size of chunk found with the read head at the end of the c= hunk. */ -static size_t unpack_u16_chunk(struct aa_ext *e, char **chunk) +VISIBLE_IF_KUNIT size_t aa_unpack_u16_chunk(struct aa_ext *e, char **chunk) { size_t size =3D 0; void *pos =3D e->pos; =20 - if (!inbounds(e, sizeof(u16))) + if (!aa_inbounds(e, sizeof(u16))) goto fail; size =3D le16_to_cpu(get_unaligned((__le16 *) e->pos)); e->pos +=3D sizeof(__le16); - if (!inbounds(e, size)) + if (!aa_inbounds(e, size)) goto fail; *chunk =3D e->pos; e->pos +=3D size; @@ -239,20 +204,22 @@ static size_t unpack_u16_chunk(struct aa_ext *e, char= **chunk) e->pos =3D pos; return 0; } +EXPORT_SYMBOL_IF_KUNIT(aa_unpack_u16_chunk); =20 /* unpack control byte */ -static bool unpack_X(struct aa_ext *e, enum aa_code code) +VISIBLE_IF_KUNIT bool aa_unpack_X(struct aa_ext *e, enum aa_code code) { - if (!inbounds(e, 1)) + if (!aa_inbounds(e, 1)) return false; if (*(u8 *) e->pos !=3D code) return false; e->pos++; return true; } +EXPORT_SYMBOL_IF_KUNIT(aa_unpack_X); =20 /** - * unpack_nameX - check is the next element is of type X with a name of @n= ame + * aa_unpack_nameX - check is the next element is of type X with a name of= @name * @e: serialized data extent information (NOT NULL) * @code: type code * @name: name to match to the serialized element. (MAYBE NULL) @@ -267,7 +234,7 @@ static bool unpack_X(struct aa_ext *e, enum aa_code cod= e) * * Returns: false if either match fails, the read head does not move */ -static bool unpack_nameX(struct aa_ext *e, enum aa_code code, const char *= name) +VISIBLE_IF_KUNIT bool aa_unpack_nameX(struct aa_ext *e, enum aa_code code,= const char *name) { /* * May need to reset pos if name or type doesn't match @@ -277,9 +244,9 @@ static bool unpack_nameX(struct aa_ext *e, enum aa_code= code, const char *name) * Check for presence of a tagname, and if present name size * AA_NAME tag value is a u16. */ - if (unpack_X(e, AA_NAME)) { + if (aa_unpack_X(e, AA_NAME)) { char *tag =3D NULL; - size_t size =3D unpack_u16_chunk(e, &tag); + size_t size =3D aa_unpack_u16_chunk(e, &tag); /* if a name is specified it must match. otherwise skip tag */ if (name && (!size || tag[size-1] !=3D '\0' || strcmp(name, tag))) goto fail; @@ -289,20 +256,21 @@ static bool unpack_nameX(struct aa_ext *e, enum aa_co= de code, const char *name) } =20 /* now check if type code matches */ - if (unpack_X(e, code)) + if (aa_unpack_X(e, code)) return true; =20 fail: e->pos =3D pos; return false; } +EXPORT_SYMBOL_IF_KUNIT(aa_unpack_nameX); =20 static bool unpack_u8(struct aa_ext *e, u8 *data, const char *name) { void *pos =3D e->pos; =20 - if (unpack_nameX(e, AA_U8, name)) { - if (!inbounds(e, sizeof(u8))) + if (aa_unpack_nameX(e, AA_U8, name)) { + if (!aa_inbounds(e, sizeof(u8))) goto fail; if (data) *data =3D *((u8 *)e->pos); @@ -315,12 +283,12 @@ static bool unpack_u8(struct aa_ext *e, u8 *data, con= st char *name) return false; } =20 -static bool unpack_u32(struct aa_ext *e, u32 *data, const char *name) +VISIBLE_IF_KUNIT bool aa_unpack_u32(struct aa_ext *e, u32 *data, const cha= r *name) { void *pos =3D e->pos; =20 - if (unpack_nameX(e, AA_U32, name)) { - if (!inbounds(e, sizeof(u32))) + if (aa_unpack_nameX(e, AA_U32, name)) { + if (!aa_inbounds(e, sizeof(u32))) goto fail; if (data) *data =3D le32_to_cpu(get_unaligned((__le32 *) e->pos)); @@ -332,13 +300,14 @@ static bool unpack_u32(struct aa_ext *e, u32 *data, c= onst char *name) e->pos =3D pos; return false; } +EXPORT_SYMBOL_IF_KUNIT(aa_unpack_u32); =20 -static bool unpack_u64(struct aa_ext *e, u64 *data, const char *name) +VISIBLE_IF_KUNIT bool aa_unpack_u64(struct aa_ext *e, u64 *data, const cha= r *name) { void *pos =3D e->pos; =20 - if (unpack_nameX(e, AA_U64, name)) { - if (!inbounds(e, sizeof(u64))) + if (aa_unpack_nameX(e, AA_U64, name)) { + if (!aa_inbounds(e, sizeof(u64))) goto fail; if (data) *data =3D le64_to_cpu(get_unaligned((__le64 *) e->pos)); @@ -350,14 +319,15 @@ static bool unpack_u64(struct aa_ext *e, u64 *data, c= onst char *name) e->pos =3D pos; return false; } +EXPORT_SYMBOL_IF_KUNIT(aa_unpack_u64); =20 -static size_t unpack_array(struct aa_ext *e, const char *name) +VISIBLE_IF_KUNIT size_t aa_unpack_array(struct aa_ext *e, const char *name) { void *pos =3D e->pos; =20 - if (unpack_nameX(e, AA_ARRAY, name)) { + if (aa_unpack_nameX(e, AA_ARRAY, name)) { int size; - if (!inbounds(e, sizeof(u16))) + if (!aa_inbounds(e, sizeof(u16))) goto fail; size =3D (int)le16_to_cpu(get_unaligned((__le16 *) e->pos)); e->pos +=3D sizeof(u16); @@ -368,18 +338,19 @@ static size_t unpack_array(struct aa_ext *e, const ch= ar *name) e->pos =3D pos; return 0; } +EXPORT_SYMBOL_IF_KUNIT(aa_unpack_array); =20 -static size_t unpack_blob(struct aa_ext *e, char **blob, const char *name) +VISIBLE_IF_KUNIT size_t aa_unpack_blob(struct aa_ext *e, char **blob, cons= t char *name) { void *pos =3D e->pos; =20 - if (unpack_nameX(e, AA_BLOB, name)) { + if (aa_unpack_nameX(e, AA_BLOB, name)) { u32 size; - if (!inbounds(e, sizeof(u32))) + if (!aa_inbounds(e, sizeof(u32))) goto fail; size =3D le32_to_cpu(get_unaligned((__le32 *) e->pos)); e->pos +=3D sizeof(u32); - if (inbounds(e, (size_t) size)) { + if (aa_inbounds(e, (size_t) size)) { *blob =3D e->pos; e->pos +=3D size; return size; @@ -390,15 +361,16 @@ static size_t unpack_blob(struct aa_ext *e, char **bl= ob, const char *name) e->pos =3D pos; return 0; } +EXPORT_SYMBOL_IF_KUNIT(aa_unpack_blob); =20 -static int unpack_str(struct aa_ext *e, const char **string, const char *n= ame) +VISIBLE_IF_KUNIT int aa_unpack_str(struct aa_ext *e, const char **string, = const char *name) { char *src_str; size_t size =3D 0; void *pos =3D e->pos; *string =3D NULL; - if (unpack_nameX(e, AA_STRING, name)) { - size =3D unpack_u16_chunk(e, &src_str); + if (aa_unpack_nameX(e, AA_STRING, name)) { + size =3D aa_unpack_u16_chunk(e, &src_str); if (size) { /* strings are null terminated, length is size - 1 */ if (src_str[size - 1] !=3D 0) @@ -413,12 +385,13 @@ static int unpack_str(struct aa_ext *e, const char **= string, const char *name) e->pos =3D pos; return 0; } +EXPORT_SYMBOL_IF_KUNIT(aa_unpack_str); =20 -static int unpack_strdup(struct aa_ext *e, char **string, const char *name) +VISIBLE_IF_KUNIT int aa_unpack_strdup(struct aa_ext *e, char **string, con= st char *name) { const char *tmp; void *pos =3D e->pos; - int res =3D unpack_str(e, &tmp, name); + int res =3D aa_unpack_str(e, &tmp, name); *string =3D NULL; =20 if (!res) @@ -432,6 +405,7 @@ static int unpack_strdup(struct aa_ext *e, char **strin= g, const char *name) =20 return res; } +EXPORT_SYMBOL_IF_KUNIT(aa_unpack_strdup); =20 =20 /** @@ -446,7 +420,7 @@ static struct aa_dfa *unpack_dfa(struct aa_ext *e) size_t size; struct aa_dfa *dfa =3D NULL; =20 - size =3D unpack_blob(e, &blob, "aadfa"); + size =3D aa_unpack_blob(e, &blob, "aadfa"); if (size) { /* * The dfa is aligned with in the blob to 8 bytes @@ -482,10 +456,10 @@ static bool unpack_trans_table(struct aa_ext *e, stru= ct aa_profile *profile) void *saved_pos =3D e->pos; =20 /* exec table is optional */ - if (unpack_nameX(e, AA_STRUCT, "xtable")) { + if (aa_unpack_nameX(e, AA_STRUCT, "xtable")) { int i, size; =20 - size =3D unpack_array(e, NULL); + size =3D aa_unpack_array(e, NULL); /* currently 4 exec bits and entries 0-3 are reserved iupcx */ if (size > 16 - 4) goto fail; @@ -497,8 +471,8 @@ static bool unpack_trans_table(struct aa_ext *e, struct= aa_profile *profile) profile->file.trans.size =3D size; for (i =3D 0; i < size; i++) { char *str; - int c, j, pos, size2 =3D unpack_strdup(e, &str, NULL); - /* unpack_strdup verifies that the last character is + int c, j, pos, size2 =3D aa_unpack_strdup(e, &str, NULL); + /* aa_unpack_strdup verifies that the last character is * null termination byte. */ if (!size2) @@ -521,7 +495,7 @@ static bool unpack_trans_table(struct aa_ext *e, struct= aa_profile *profile) goto fail; /* beginning with : requires an embedded \0, * verify that exactly 1 internal \0 exists - * trailing \0 already verified by unpack_strdup + * trailing \0 already verified by aa_unpack_strdup * * convert \0 back to : for label_parse */ @@ -533,9 +507,9 @@ static bool unpack_trans_table(struct aa_ext *e, struct= aa_profile *profile) /* fail - all other cases with embedded \0 */ goto fail; } - if (!unpack_nameX(e, AA_ARRAYEND, NULL)) + if (!aa_unpack_nameX(e, AA_ARRAYEND, NULL)) goto fail; - if (!unpack_nameX(e, AA_STRUCTEND, NULL)) + if (!aa_unpack_nameX(e, AA_STRUCTEND, NULL)) goto fail; } return true; @@ -550,21 +524,21 @@ static bool unpack_xattrs(struct aa_ext *e, struct aa= _profile *profile) { void *pos =3D e->pos; =20 - if (unpack_nameX(e, AA_STRUCT, "xattrs")) { + if (aa_unpack_nameX(e, AA_STRUCT, "xattrs")) { int i, size; =20 - size =3D unpack_array(e, NULL); + size =3D aa_unpack_array(e, NULL); profile->xattr_count =3D size; profile->xattrs =3D kcalloc(size, sizeof(char *), GFP_KERNEL); if (!profile->xattrs) goto fail; for (i =3D 0; i < size; i++) { - if (!unpack_strdup(e, &profile->xattrs[i], NULL)) + if (!aa_unpack_strdup(e, &profile->xattrs[i], NULL)) goto fail; } - if (!unpack_nameX(e, AA_ARRAYEND, NULL)) + if (!aa_unpack_nameX(e, AA_ARRAYEND, NULL)) goto fail; - if (!unpack_nameX(e, AA_STRUCTEND, NULL)) + if (!aa_unpack_nameX(e, AA_STRUCTEND, NULL)) goto fail; } =20 @@ -580,8 +554,8 @@ static bool unpack_secmark(struct aa_ext *e, struct aa_= profile *profile) void *pos =3D e->pos; int i, size; =20 - if (unpack_nameX(e, AA_STRUCT, "secmark")) { - size =3D unpack_array(e, NULL); + if (aa_unpack_nameX(e, AA_STRUCT, "secmark")) { + size =3D aa_unpack_array(e, NULL); =20 profile->secmark =3D kcalloc(size, sizeof(struct aa_secmark), GFP_KERNEL); @@ -595,12 +569,12 @@ static bool unpack_secmark(struct aa_ext *e, struct a= a_profile *profile) goto fail; if (!unpack_u8(e, &profile->secmark[i].deny, NULL)) goto fail; - if (!unpack_strdup(e, &profile->secmark[i].label, NULL)) + if (!aa_unpack_strdup(e, &profile->secmark[i].label, NULL)) goto fail; } - if (!unpack_nameX(e, AA_ARRAYEND, NULL)) + if (!aa_unpack_nameX(e, AA_ARRAYEND, NULL)) goto fail; - if (!unpack_nameX(e, AA_STRUCTEND, NULL)) + if (!aa_unpack_nameX(e, AA_STRUCTEND, NULL)) goto fail; } =20 @@ -624,26 +598,26 @@ static bool unpack_rlimits(struct aa_ext *e, struct a= a_profile *profile) void *pos =3D e->pos; =20 /* rlimits are optional */ - if (unpack_nameX(e, AA_STRUCT, "rlimits")) { + if (aa_unpack_nameX(e, AA_STRUCT, "rlimits")) { int i, size; u32 tmp =3D 0; - if (!unpack_u32(e, &tmp, NULL)) + if (!aa_unpack_u32(e, &tmp, NULL)) goto fail; profile->rlimits.mask =3D tmp; =20 - size =3D unpack_array(e, NULL); + size =3D aa_unpack_array(e, NULL); if (size > RLIM_NLIMITS) goto fail; for (i =3D 0; i < size; i++) { u64 tmp2 =3D 0; int a =3D aa_map_resource(i); - if (!unpack_u64(e, &tmp2, NULL)) + if (!aa_unpack_u64(e, &tmp2, NULL)) goto fail; profile->rlimits.limits[a].rlim_max =3D tmp2; } - if (!unpack_nameX(e, AA_ARRAYEND, NULL)) + if (!aa_unpack_nameX(e, AA_ARRAYEND, NULL)) goto fail; - if (!unpack_nameX(e, AA_STRUCTEND, NULL)) + if (!aa_unpack_nameX(e, AA_STRUCTEND, NULL)) goto fail; } return true; @@ -691,9 +665,9 @@ static struct aa_profile *unpack_profile(struct aa_ext = *e, char **ns_name) *ns_name =3D NULL; =20 /* check that we have the right struct being passed */ - if (!unpack_nameX(e, AA_STRUCT, "profile")) + if (!aa_unpack_nameX(e, AA_STRUCT, "profile")) goto fail; - if (!unpack_str(e, &name, NULL)) + if (!aa_unpack_str(e, &name, NULL)) goto fail; if (*name =3D=3D '\0') goto fail; @@ -713,10 +687,10 @@ static struct aa_profile *unpack_profile(struct aa_ex= t *e, char **ns_name) return ERR_PTR(-ENOMEM); =20 /* profile renaming is optional */ - (void) unpack_str(e, &profile->rename, "rename"); + (void) aa_unpack_str(e, &profile->rename, "rename"); =20 /* attachment string is optional */ - (void) unpack_str(e, &profile->attach, "attach"); + (void) aa_unpack_str(e, &profile->attach, "attach"); =20 /* xmatch is optional and may be NULL */ profile->xmatch =3D unpack_dfa(e); @@ -728,7 +702,7 @@ static struct aa_profile *unpack_profile(struct aa_ext = *e, char **ns_name) } /* xmatch_len is not optional if xmatch is set */ if (profile->xmatch) { - if (!unpack_u32(e, &tmp, NULL)) { + if (!aa_unpack_u32(e, &tmp, NULL)) { info =3D "missing xmatch len"; goto fail; } @@ -736,15 +710,15 @@ static struct aa_profile *unpack_profile(struct aa_ex= t *e, char **ns_name) } =20 /* disconnected attachment string is optional */ - (void) unpack_str(e, &profile->disconnected, "disconnected"); + (void) aa_unpack_str(e, &profile->disconnected, "disconnected"); =20 /* per profile debug flags (complain, audit) */ - if (!unpack_nameX(e, AA_STRUCT, "flags")) { + if (!aa_unpack_nameX(e, AA_STRUCT, "flags")) { info =3D "profile missing flags"; goto fail; } info =3D "failed to unpack profile flags"; - if (!unpack_u32(e, &tmp, NULL)) + if (!aa_unpack_u32(e, &tmp, NULL)) goto fail; if (tmp & PACKED_FLAG_HAT) profile->label.flags |=3D FLAG_HAT; @@ -752,7 +726,7 @@ static struct aa_profile *unpack_profile(struct aa_ext = *e, char **ns_name) profile->label.flags |=3D FLAG_DEBUG1; if (tmp & PACKED_FLAG_DEBUG2) profile->label.flags |=3D FLAG_DEBUG2; - if (!unpack_u32(e, &tmp, NULL)) + if (!aa_unpack_u32(e, &tmp, NULL)) goto fail; if (tmp =3D=3D PACKED_MODE_COMPLAIN || (e->version & FORCE_COMPLAIN_FLAG)= ) { profile->mode =3D APPARMOR_COMPLAIN; @@ -766,16 +740,16 @@ static struct aa_profile *unpack_profile(struct aa_ex= t *e, char **ns_name) } else { goto fail; } - if (!unpack_u32(e, &tmp, NULL)) + if (!aa_unpack_u32(e, &tmp, NULL)) goto fail; if (tmp) profile->audit =3D AUDIT_ALL; =20 - if (!unpack_nameX(e, AA_STRUCTEND, NULL)) + if (!aa_unpack_nameX(e, AA_STRUCTEND, NULL)) goto fail; =20 /* path_flags is optional */ - if (unpack_u32(e, &profile->path_flags, "path_flags")) + if (aa_unpack_u32(e, &profile->path_flags, "path_flags")) profile->path_flags |=3D profile->label.flags & PATH_MEDIATE_DELETED; else @@ -783,38 +757,38 @@ static struct aa_profile *unpack_profile(struct aa_ex= t *e, char **ns_name) profile->path_flags =3D PATH_MEDIATE_DELETED; =20 info =3D "failed to unpack profile capabilities"; - if (!unpack_u32(e, &(profile->caps.allow.cap[0]), NULL)) + if (!aa_unpack_u32(e, &(profile->caps.allow.cap[0]), NULL)) goto fail; - if (!unpack_u32(e, &(profile->caps.audit.cap[0]), NULL)) + if (!aa_unpack_u32(e, &(profile->caps.audit.cap[0]), NULL)) goto fail; - if (!unpack_u32(e, &(profile->caps.quiet.cap[0]), NULL)) + if (!aa_unpack_u32(e, &(profile->caps.quiet.cap[0]), NULL)) goto fail; - if (!unpack_u32(e, &tmpcap.cap[0], NULL)) + if (!aa_unpack_u32(e, &tmpcap.cap[0], NULL)) goto fail; =20 info =3D "failed to unpack upper profile capabilities"; - if (unpack_nameX(e, AA_STRUCT, "caps64")) { + if (aa_unpack_nameX(e, AA_STRUCT, "caps64")) { /* optional upper half of 64 bit caps */ - if (!unpack_u32(e, &(profile->caps.allow.cap[1]), NULL)) + if (!aa_unpack_u32(e, &(profile->caps.allow.cap[1]), NULL)) goto fail; - if (!unpack_u32(e, &(profile->caps.audit.cap[1]), NULL)) + if (!aa_unpack_u32(e, &(profile->caps.audit.cap[1]), NULL)) goto fail; - if (!unpack_u32(e, &(profile->caps.quiet.cap[1]), NULL)) + if (!aa_unpack_u32(e, &(profile->caps.quiet.cap[1]), NULL)) goto fail; - if (!unpack_u32(e, &(tmpcap.cap[1]), NULL)) + if (!aa_unpack_u32(e, &(tmpcap.cap[1]), NULL)) goto fail; - if (!unpack_nameX(e, AA_STRUCTEND, NULL)) + if (!aa_unpack_nameX(e, AA_STRUCTEND, NULL)) goto fail; } =20 info =3D "failed to unpack extended profile capabilities"; - if (unpack_nameX(e, AA_STRUCT, "capsx")) { + if (aa_unpack_nameX(e, AA_STRUCT, "capsx")) { /* optional extended caps mediation mask */ - if (!unpack_u32(e, &(profile->caps.extended.cap[0]), NULL)) + if (!aa_unpack_u32(e, &(profile->caps.extended.cap[0]), NULL)) goto fail; - if (!unpack_u32(e, &(profile->caps.extended.cap[1]), NULL)) + if (!aa_unpack_u32(e, &(profile->caps.extended.cap[1]), NULL)) goto fail; - if (!unpack_nameX(e, AA_STRUCTEND, NULL)) + if (!aa_unpack_nameX(e, AA_STRUCTEND, NULL)) goto fail; } =20 @@ -833,7 +807,7 @@ static struct aa_profile *unpack_profile(struct aa_ext = *e, char **ns_name) goto fail; } =20 - if (unpack_nameX(e, AA_STRUCT, "policydb")) { + if (aa_unpack_nameX(e, AA_STRUCT, "policydb")) { /* generic policy dfa - optional and may be NULL */ info =3D "failed to unpack policydb"; profile->policy.dfa =3D unpack_dfa(e); @@ -845,7 +819,7 @@ static struct aa_profile *unpack_profile(struct aa_ext = *e, char **ns_name) error =3D -EPROTO; goto fail; } - if (!unpack_u32(e, &profile->policy.start[0], "start")) + if (!aa_unpack_u32(e, &profile->policy.start[0], "start")) /* default start state */ profile->policy.start[0] =3D DFA_START; /* setup class index */ @@ -855,7 +829,7 @@ static struct aa_profile *unpack_profile(struct aa_ext = *e, char **ns_name) profile->policy.start[0], i); } - if (!unpack_nameX(e, AA_STRUCTEND, NULL)) + if (!aa_unpack_nameX(e, AA_STRUCTEND, NULL)) goto fail; } else profile->policy.dfa =3D aa_get_dfa(nulldfa); @@ -868,7 +842,7 @@ static struct aa_profile *unpack_profile(struct aa_ext = *e, char **ns_name) info =3D "failed to unpack profile file rules"; goto fail; } else if (profile->file.dfa) { - if (!unpack_u32(e, &profile->file.start, "dfa_start")) + if (!aa_unpack_u32(e, &profile->file.start, "dfa_start")) /* default start state */ profile->file.start =3D DFA_START; } else if (profile->policy.dfa && @@ -883,7 +857,7 @@ static struct aa_profile *unpack_profile(struct aa_ext = *e, char **ns_name) goto fail; } =20 - if (unpack_nameX(e, AA_STRUCT, "data")) { + if (aa_unpack_nameX(e, AA_STRUCT, "data")) { info =3D "out of memory"; profile->data =3D kzalloc(sizeof(*profile->data), GFP_KERNEL); if (!profile->data) @@ -901,7 +875,7 @@ static struct aa_profile *unpack_profile(struct aa_ext = *e, char **ns_name) goto fail; } =20 - while (unpack_strdup(e, &key, NULL)) { + while (aa_unpack_strdup(e, &key, NULL)) { data =3D kzalloc(sizeof(*data), GFP_KERNEL); if (!data) { kfree_sensitive(key); @@ -909,7 +883,7 @@ static struct aa_profile *unpack_profile(struct aa_ext = *e, char **ns_name) } =20 data->key =3D key; - data->size =3D unpack_blob(e, &data->data, NULL); + data->size =3D aa_unpack_blob(e, &data->data, NULL); data->data =3D kvmemdup(data->data, data->size); if (data->size && !data->data) { kfree_sensitive(data->key); @@ -921,13 +895,13 @@ static struct aa_profile *unpack_profile(struct aa_ex= t *e, char **ns_name) profile->data->p); } =20 - if (!unpack_nameX(e, AA_STRUCTEND, NULL)) { + if (!aa_unpack_nameX(e, AA_STRUCTEND, NULL)) { info =3D "failed to unpack end of key, value data table"; goto fail; } } =20 - if (!unpack_nameX(e, AA_STRUCTEND, NULL)) { + if (!aa_unpack_nameX(e, AA_STRUCTEND, NULL)) { info =3D "failed to unpack end of profile"; goto fail; } @@ -960,7 +934,7 @@ static int verify_header(struct aa_ext *e, int required= , const char **ns) *ns =3D NULL; =20 /* get the interface version */ - if (!unpack_u32(e, &e->version, "version")) { + if (!aa_unpack_u32(e, &e->version, "version")) { if (required) { audit_iface(NULL, NULL, NULL, "invalid profile format", e, error); @@ -979,7 +953,7 @@ static int verify_header(struct aa_ext *e, int required= , const char **ns) } =20 /* read the namespace if present */ - if (unpack_str(e, &name, "namespace")) { + if (aa_unpack_str(e, &name, "namespace")) { if (*name =3D=3D '\0') { audit_iface(NULL, NULL, NULL, "invalid namespace name", e, error); @@ -1251,7 +1225,3 @@ int aa_unpack(struct aa_loaddata *udata, struct list_= head *lh, =20 return error; } - -#ifdef CONFIG_SECURITY_APPARMOR_KUNIT_TEST -#include "policy_unpack_test.c" -#endif /* CONFIG_SECURITY_APPARMOR_KUNIT_TEST */ diff --git a/security/apparmor/policy_unpack_test.c b/security/apparmor/pol= icy_unpack_test.c index 0a969b2e03db..f25cf2a023d5 100644 --- a/security/apparmor/policy_unpack_test.c +++ b/security/apparmor/policy_unpack_test.c @@ -4,6 +4,7 @@ */ =20 #include +#include =20 #include "include/policy.h" #include "include/policy_unpack.h" @@ -43,6 +44,8 @@ #define TEST_ARRAY_BUF_OFFSET \ (TEST_NAMED_ARRAY_BUF_OFFSET + 3 + strlen(TEST_ARRAY_NAME) + 1) =20 +MODULE_IMPORT_NS(EXPORTED_FOR_KUNIT_TESTING); + struct policy_unpack_fixture { struct aa_ext *e; size_t e_size; @@ -125,16 +128,16 @@ static void policy_unpack_test_inbounds_when_inbounds= (struct kunit *test) { struct policy_unpack_fixture *puf =3D test->priv; =20 - KUNIT_EXPECT_TRUE(test, inbounds(puf->e, 0)); - KUNIT_EXPECT_TRUE(test, inbounds(puf->e, puf->e_size / 2)); - KUNIT_EXPECT_TRUE(test, inbounds(puf->e, puf->e_size)); + KUNIT_EXPECT_TRUE(test, aa_inbounds(puf->e, 0)); + KUNIT_EXPECT_TRUE(test, aa_inbounds(puf->e, puf->e_size / 2)); + KUNIT_EXPECT_TRUE(test, aa_inbounds(puf->e, puf->e_size)); } =20 static void policy_unpack_test_inbounds_when_out_of_bounds(struct kunit *t= est) { struct policy_unpack_fixture *puf =3D test->priv; =20 - KUNIT_EXPECT_FALSE(test, inbounds(puf->e, puf->e_size + 1)); + KUNIT_EXPECT_FALSE(test, aa_inbounds(puf->e, puf->e_size + 1)); } =20 static void policy_unpack_test_unpack_array_with_null_name(struct kunit *t= est) @@ -144,7 +147,7 @@ static void policy_unpack_test_unpack_array_with_null_n= ame(struct kunit *test) =20 puf->e->pos +=3D TEST_ARRAY_BUF_OFFSET; =20 - array_size =3D unpack_array(puf->e, NULL); + array_size =3D aa_unpack_array(puf->e, NULL); =20 KUNIT_EXPECT_EQ(test, array_size, (u16)TEST_ARRAY_SIZE); KUNIT_EXPECT_PTR_EQ(test, puf->e->pos, @@ -159,7 +162,7 @@ static void policy_unpack_test_unpack_array_with_name(s= truct kunit *test) =20 puf->e->pos +=3D TEST_NAMED_ARRAY_BUF_OFFSET; =20 - array_size =3D unpack_array(puf->e, name); + array_size =3D aa_unpack_array(puf->e, name); =20 KUNIT_EXPECT_EQ(test, array_size, (u16)TEST_ARRAY_SIZE); KUNIT_EXPECT_PTR_EQ(test, puf->e->pos, @@ -175,7 +178,7 @@ static void policy_unpack_test_unpack_array_out_of_boun= ds(struct kunit *test) puf->e->pos +=3D TEST_NAMED_ARRAY_BUF_OFFSET; puf->e->end =3D puf->e->start + TEST_ARRAY_BUF_OFFSET + sizeof(u16); =20 - array_size =3D unpack_array(puf->e, name); + array_size =3D aa_unpack_array(puf->e, name); =20 KUNIT_EXPECT_EQ(test, array_size, 0); KUNIT_EXPECT_PTR_EQ(test, puf->e->pos, @@ -189,7 +192,7 @@ static void policy_unpack_test_unpack_blob_with_null_na= me(struct kunit *test) size_t size; =20 puf->e->pos +=3D TEST_BLOB_BUF_OFFSET; - size =3D unpack_blob(puf->e, &blob, NULL); + size =3D aa_unpack_blob(puf->e, &blob, NULL); =20 KUNIT_ASSERT_EQ(test, size, TEST_BLOB_DATA_SIZE); KUNIT_EXPECT_TRUE(test, @@ -203,7 +206,7 @@ static void policy_unpack_test_unpack_blob_with_name(st= ruct kunit *test) size_t size; =20 puf->e->pos +=3D TEST_NAMED_BLOB_BUF_OFFSET; - size =3D unpack_blob(puf->e, &blob, TEST_BLOB_NAME); + size =3D aa_unpack_blob(puf->e, &blob, TEST_BLOB_NAME); =20 KUNIT_ASSERT_EQ(test, size, TEST_BLOB_DATA_SIZE); KUNIT_EXPECT_TRUE(test, @@ -222,7 +225,7 @@ static void policy_unpack_test_unpack_blob_out_of_bound= s(struct kunit *test) puf->e->end =3D puf->e->start + TEST_BLOB_BUF_OFFSET + TEST_BLOB_DATA_SIZE - 1; =20 - size =3D unpack_blob(puf->e, &blob, TEST_BLOB_NAME); + size =3D aa_unpack_blob(puf->e, &blob, TEST_BLOB_NAME); =20 KUNIT_EXPECT_EQ(test, size, 0); KUNIT_EXPECT_PTR_EQ(test, puf->e->pos, start); @@ -235,7 +238,7 @@ static void policy_unpack_test_unpack_str_with_null_nam= e(struct kunit *test) size_t size; =20 puf->e->pos +=3D TEST_STRING_BUF_OFFSET; - size =3D unpack_str(puf->e, &string, NULL); + size =3D aa_unpack_str(puf->e, &string, NULL); =20 KUNIT_EXPECT_EQ(test, size, strlen(TEST_STRING_DATA) + 1); KUNIT_EXPECT_STREQ(test, string, TEST_STRING_DATA); @@ -247,7 +250,7 @@ static void policy_unpack_test_unpack_str_with_name(str= uct kunit *test) const char *string =3D NULL; size_t size; =20 - size =3D unpack_str(puf->e, &string, TEST_STRING_NAME); + size =3D aa_unpack_str(puf->e, &string, TEST_STRING_NAME); =20 KUNIT_EXPECT_EQ(test, size, strlen(TEST_STRING_DATA) + 1); KUNIT_EXPECT_STREQ(test, string, TEST_STRING_DATA); @@ -263,7 +266,7 @@ static void policy_unpack_test_unpack_str_out_of_bounds= (struct kunit *test) puf->e->end =3D puf->e->pos + TEST_STRING_BUF_OFFSET + strlen(TEST_STRING_DATA) - 1; =20 - size =3D unpack_str(puf->e, &string, TEST_STRING_NAME); + size =3D aa_unpack_str(puf->e, &string, TEST_STRING_NAME); =20 KUNIT_EXPECT_EQ(test, size, 0); KUNIT_EXPECT_PTR_EQ(test, puf->e->pos, start); @@ -276,7 +279,7 @@ static void policy_unpack_test_unpack_strdup_with_null_= name(struct kunit *test) size_t size; =20 puf->e->pos +=3D TEST_STRING_BUF_OFFSET; - size =3D unpack_strdup(puf->e, &string, NULL); + size =3D aa_unpack_strdup(puf->e, &string, NULL); =20 KUNIT_EXPECT_EQ(test, size, strlen(TEST_STRING_DATA) + 1); KUNIT_EXPECT_FALSE(test, @@ -291,7 +294,7 @@ static void policy_unpack_test_unpack_strdup_with_name(= struct kunit *test) char *string =3D NULL; size_t size; =20 - size =3D unpack_strdup(puf->e, &string, TEST_STRING_NAME); + size =3D aa_unpack_strdup(puf->e, &string, TEST_STRING_NAME); =20 KUNIT_EXPECT_EQ(test, size, strlen(TEST_STRING_DATA) + 1); KUNIT_EXPECT_FALSE(test, @@ -310,7 +313,7 @@ static void policy_unpack_test_unpack_strdup_out_of_bou= nds(struct kunit *test) puf->e->end =3D puf->e->pos + TEST_STRING_BUF_OFFSET + strlen(TEST_STRING_DATA) - 1; =20 - size =3D unpack_strdup(puf->e, &string, TEST_STRING_NAME); + size =3D aa_unpack_strdup(puf->e, &string, TEST_STRING_NAME); =20 KUNIT_EXPECT_EQ(test, size, 0); KUNIT_EXPECT_NULL(test, string); @@ -324,7 +327,7 @@ static void policy_unpack_test_unpack_nameX_with_null_n= ame(struct kunit *test) =20 puf->e->pos +=3D TEST_U32_BUF_OFFSET; =20 - success =3D unpack_nameX(puf->e, AA_U32, NULL); + success =3D aa_unpack_nameX(puf->e, AA_U32, NULL); =20 KUNIT_EXPECT_TRUE(test, success); KUNIT_EXPECT_PTR_EQ(test, puf->e->pos, @@ -338,7 +341,7 @@ static void policy_unpack_test_unpack_nameX_with_wrong_= code(struct kunit *test) =20 puf->e->pos +=3D TEST_U32_BUF_OFFSET; =20 - success =3D unpack_nameX(puf->e, AA_BLOB, NULL); + success =3D aa_unpack_nameX(puf->e, AA_BLOB, NULL); =20 KUNIT_EXPECT_FALSE(test, success); KUNIT_EXPECT_PTR_EQ(test, puf->e->pos, @@ -353,7 +356,7 @@ static void policy_unpack_test_unpack_nameX_with_name(s= truct kunit *test) =20 puf->e->pos +=3D TEST_NAMED_U32_BUF_OFFSET; =20 - success =3D unpack_nameX(puf->e, AA_U32, name); + success =3D aa_unpack_nameX(puf->e, AA_U32, name); =20 KUNIT_EXPECT_TRUE(test, success); KUNIT_EXPECT_PTR_EQ(test, puf->e->pos, @@ -368,7 +371,7 @@ static void policy_unpack_test_unpack_nameX_with_wrong_= name(struct kunit *test) =20 puf->e->pos +=3D TEST_NAMED_U32_BUF_OFFSET; =20 - success =3D unpack_nameX(puf->e, AA_U32, name); + success =3D aa_unpack_nameX(puf->e, AA_U32, name); =20 KUNIT_EXPECT_FALSE(test, success); KUNIT_EXPECT_PTR_EQ(test, puf->e->pos, @@ -389,7 +392,7 @@ static void policy_unpack_test_unpack_u16_chunk_basic(s= truct kunit *test) */ puf->e->end +=3D TEST_U16_DATA; =20 - size =3D unpack_u16_chunk(puf->e, &chunk); + size =3D aa_unpack_u16_chunk(puf->e, &chunk); =20 KUNIT_EXPECT_PTR_EQ(test, chunk, puf->e->start + TEST_U16_OFFSET + 2); @@ -406,7 +409,7 @@ static void policy_unpack_test_unpack_u16_chunk_out_of_= bounds_1( =20 puf->e->pos =3D puf->e->end - 1; =20 - size =3D unpack_u16_chunk(puf->e, &chunk); + size =3D aa_unpack_u16_chunk(puf->e, &chunk); =20 KUNIT_EXPECT_EQ(test, size, 0); KUNIT_EXPECT_NULL(test, chunk); @@ -428,7 +431,7 @@ static void policy_unpack_test_unpack_u16_chunk_out_of_= bounds_2( */ puf->e->end =3D puf->e->pos + TEST_U16_DATA - 1; =20 - size =3D unpack_u16_chunk(puf->e, &chunk); + size =3D aa_unpack_u16_chunk(puf->e, &chunk); =20 KUNIT_EXPECT_EQ(test, size, 0); KUNIT_EXPECT_NULL(test, chunk); @@ -443,7 +446,7 @@ static void policy_unpack_test_unpack_u32_with_null_nam= e(struct kunit *test) =20 puf->e->pos +=3D TEST_U32_BUF_OFFSET; =20 - success =3D unpack_u32(puf->e, &data, NULL); + success =3D aa_unpack_u32(puf->e, &data, NULL); =20 KUNIT_EXPECT_TRUE(test, success); KUNIT_EXPECT_EQ(test, data, TEST_U32_DATA); @@ -460,7 +463,7 @@ static void policy_unpack_test_unpack_u32_with_name(str= uct kunit *test) =20 puf->e->pos +=3D TEST_NAMED_U32_BUF_OFFSET; =20 - success =3D unpack_u32(puf->e, &data, name); + success =3D aa_unpack_u32(puf->e, &data, name); =20 KUNIT_EXPECT_TRUE(test, success); KUNIT_EXPECT_EQ(test, data, TEST_U32_DATA); @@ -478,7 +481,7 @@ static void policy_unpack_test_unpack_u32_out_of_bounds= (struct kunit *test) puf->e->pos +=3D TEST_NAMED_U32_BUF_OFFSET; puf->e->end =3D puf->e->start + TEST_U32_BUF_OFFSET + sizeof(u32); =20 - success =3D unpack_u32(puf->e, &data, name); + success =3D aa_unpack_u32(puf->e, &data, name); =20 KUNIT_EXPECT_FALSE(test, success); KUNIT_EXPECT_PTR_EQ(test, puf->e->pos, @@ -493,7 +496,7 @@ static void policy_unpack_test_unpack_u64_with_null_nam= e(struct kunit *test) =20 puf->e->pos +=3D TEST_U64_BUF_OFFSET; =20 - success =3D unpack_u64(puf->e, &data, NULL); + success =3D aa_unpack_u64(puf->e, &data, NULL); =20 KUNIT_EXPECT_TRUE(test, success); KUNIT_EXPECT_EQ(test, data, TEST_U64_DATA); @@ -510,7 +513,7 @@ static void policy_unpack_test_unpack_u64_with_name(str= uct kunit *test) =20 puf->e->pos +=3D TEST_NAMED_U64_BUF_OFFSET; =20 - success =3D unpack_u64(puf->e, &data, name); + success =3D aa_unpack_u64(puf->e, &data, name); =20 KUNIT_EXPECT_TRUE(test, success); KUNIT_EXPECT_EQ(test, data, TEST_U64_DATA); @@ -528,7 +531,7 @@ static void policy_unpack_test_unpack_u64_out_of_bounds= (struct kunit *test) puf->e->pos +=3D TEST_NAMED_U64_BUF_OFFSET; puf->e->end =3D puf->e->start + TEST_U64_BUF_OFFSET + sizeof(u64); =20 - success =3D unpack_u64(puf->e, &data, name); + success =3D aa_unpack_u64(puf->e, &data, name); =20 KUNIT_EXPECT_FALSE(test, success); KUNIT_EXPECT_PTR_EQ(test, puf->e->pos, @@ -538,7 +541,7 @@ static void policy_unpack_test_unpack_u64_out_of_bounds= (struct kunit *test) static void policy_unpack_test_unpack_X_code_match(struct kunit *test) { struct policy_unpack_fixture *puf =3D test->priv; - bool success =3D unpack_X(puf->e, AA_NAME); + bool success =3D aa_unpack_X(puf->e, AA_NAME); =20 KUNIT_EXPECT_TRUE(test, success); KUNIT_EXPECT_TRUE(test, puf->e->pos =3D=3D puf->e->start + 1); @@ -547,7 +550,7 @@ static void policy_unpack_test_unpack_X_code_match(stru= ct kunit *test) static void policy_unpack_test_unpack_X_code_mismatch(struct kunit *test) { struct policy_unpack_fixture *puf =3D test->priv; - bool success =3D unpack_X(puf->e, AA_STRING); + bool success =3D aa_unpack_X(puf->e, AA_STRING); =20 KUNIT_EXPECT_FALSE(test, success); KUNIT_EXPECT_TRUE(test, puf->e->pos =3D=3D puf->e->start); @@ -559,7 +562,7 @@ static void policy_unpack_test_unpack_X_out_of_bounds(s= truct kunit *test) bool success; =20 puf->e->pos =3D puf->e->end; - success =3D unpack_X(puf->e, AA_NAME); + success =3D aa_unpack_X(puf->e, AA_NAME); =20 KUNIT_EXPECT_FALSE(test, success); } @@ -605,3 +608,5 @@ static struct kunit_suite apparmor_policy_unpack_test_m= odule =3D { }; =20 kunit_test_suite(apparmor_policy_unpack_test_module); + +MODULE_LICENSE("GPL"); --=20 2.39.0.rc0.267.gcb52ba06e7-goog