]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
netfilter: bpf: Pass string literal as format argument of request_module()
authorSimon Horman <horms@kernel.org>
Mon, 11 Nov 2024 14:47:51 +0000 (14:47 +0000)
committerPablo Neira Ayuso <pablo@netfilter.org>
Thu, 14 Nov 2024 11:39:50 +0000 (12:39 +0100)
Both gcc-14 and clang-18 report that passing a non-string literal as the
format argument of request_module() is potentially insecure.

E.g. clang-18 says:

.../nf_bpf_link.c:46:24: warning: format string is not a string literal (potentially insecure) [-Wformat-security]
   46 |                 err = request_module(mod);
      |                                      ^~~
.../kmod.h:25:55: note: expanded from macro 'request_module'
   25 | #define request_module(mod...) __request_module(true, mod)
      |                                                       ^~~
.../nf_bpf_link.c:46:24: note: treat the string as an argument to avoid this
   46 |                 err = request_module(mod);
      |                                      ^
      |                                      "%s",
.../kmod.h:25:55: note: expanded from macro 'request_module'
   25 | #define request_module(mod...) __request_module(true, mod)
      |                                                       ^

It is always the case where the contents of mod is safe to pass as the
format argument. That is, in my understanding, it never contains any
format escape sequences.

But, it seems better to be safe than sorry. And, as a bonus, compiler
output becomes less verbose by addressing this issue as suggested by
clang-18.

Compile tested only.

Signed-off-by: Simon Horman <horms@kernel.org>
Reviewed-by: Toke Høiland-Jørgensen <toke@redhat.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
net/netfilter/nf_bpf_link.c

index 3d64a4511fcfdd93b0d34c0fbed8bc6f8515ec4b..06b08484470034f9e0b8318f55972409d8d39372 100644 (file)
@@ -43,7 +43,7 @@ get_proto_defrag_hook(struct bpf_nf_link *link,
        hook = rcu_dereference(*ptr_global_hook);
        if (!hook) {
                rcu_read_unlock();
-               err = request_module(mod);
+               err = request_module("%s", mod);
                if (err)
                        return ERR_PTR(err < 0 ? err : -EINVAL);