netfilter-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: James Dingwall <james@dingwall.me.uk>
To: netfilter-devel@vger.kernel.org
Subject: ulogd: out of bounds array access in ulogd_filter_HWHDR
Date: Mon, 13 Jan 2025 10:33:10 +0000	[thread overview]
Message-ID: <Z4Tr5p19Uoc1UEcg@dingwall.me.uk> (raw)

[-- Attachment #1: Type: text/plain, Size: 1795 bytes --]

Hi,

I've been given an account in the bugzilla but on submitting:

Forbidden

You don't have permission to access this resource.


Here's what I'm trying to report...

Thanks,
James



This report relates to https://bugs.launchpad.net/ubuntu/+source/ulogd2/+bug/2080677.

# apt-cache policy ulogd2
ulogd2:
  Installed: 2.0.8-2build1
  Candidate: 2.0.8-2build1
  Version table:
 *** 2.0.8-2build1 500
        500 http://gb.archive.ubuntu.com/ubuntu noble/universe amd64 Packages
        100 /var/lib/dpkg/status

# lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 24.04.1 LTS
Release: 24.04
Codename: noble

It seems that there is an out of bounds array access in ulogd_filter_HWHDR.c
which leads to ulogd2 being terminated with SIGABRT and the following message
when it is compiled with -D_FORTIFY_SOURCE=3:

*** buffer overflow detected ***

The hwac_str array is defined as:

  static char hwmac_str[MAX_KEY - START_KEY][HWADDR_LENGTH];

Which translates to:

  static char hwmac_str[4 - 2][128];

i.e. an array of two elements, valid indexes 0, 1.

Adding a debug print statement in the parse_mac2str function:

  fprintf(stderr, "using hwmac_str index %d\n", okey - START_KEY);

will result in the following message:  

  using hwmac_str index 2

So the for loop attempts to format the mac address in to an invalid index in
hwmac_str.

As a simple test I made the definition of hwmac_str an array of 3 elements
which prevented the crash.  I don't know if it is correct to simply make
the array longer or if the bug is actually in the value of 'okey' passed to
the function.  However based on the final return in interp_mac2str I think
the array definition is too short.  The attached patch allows ulog2 to
run after rebuilding with dpkg-buildpackage.

[-- Attachment #2: ulogd_filter_HWHDR-hwmac_str.patch --]
[-- Type: text/x-diff, Size: 393 bytes --]

--- filter/ulogd_filter_HWHDR.c.orig	2025-01-13 09:25:18.937977335 +0000
+++ filter/ulogd_filter_HWHDR.c	2025-01-13 09:25:51.337824820 +0000
@@ -109,7 +109,7 @@
 	},
 };
 
-static char hwmac_str[MAX_KEY - START_KEY][HWADDR_LENGTH];
+static char hwmac_str[(MAX_KEY + 1) - START_KEY][HWADDR_LENGTH];
 
 static int parse_mac2str(struct ulogd_key *ret, unsigned char *mac,
 			 int okey, int len)

             reply	other threads:[~2025-01-13 10:50 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-01-13 10:33 James Dingwall [this message]
2025-01-13 11:12 ` ulogd: out of bounds array access in ulogd_filter_HWHDR Jeremy Sowden
2025-01-13 12:30   ` Pablo Neira Ayuso
2025-01-13 12:32     ` Jeremy Sowden
2025-01-13 22:23 ` bugzilla forbiden issue [was Re: ulogd: out of bounds array access in ulogd_filter_HWHDR] Pablo Neira Ayuso
2025-01-14  0:29   ` Florian Westphal

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=Z4Tr5p19Uoc1UEcg@dingwall.me.uk \
    --to=james@dingwall.me.uk \
    --cc=netfilter-devel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).