old code unconditionally iterated dev->hard_header_len bytes, assuming the SKB's MAC header is always exactly that long. If the actual mac header in the packet is smaller, the loop reads past the MAC and logs ip/ipv6 header as if it was part of the address. Use skb_mac_header_len() as the base length, then clamp the result to dev->hard_header_len so we never read beyond what the device actually uses for its hard header, even if mac header was mangled. LLM finding, no bug was ever reported about this. Fixes: 7eb9282cd0ef ("netfilter: ipt_LOG/ip6t_LOG: add option to print decoded MAC header") Reviewed-by: Fernando Fernandez Mancera Signed-off-by: Florian Westphal --- net/netfilter/nf_log_syslog.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/net/netfilter/nf_log_syslog.c b/net/netfilter/nf_log_syslog.c index 910f6975cdf7..5f7435caff22 100644 --- a/net/netfilter/nf_log_syslog.c +++ b/net/netfilter/nf_log_syslog.c @@ -815,14 +815,17 @@ static void dump_mac_header(struct nf_log_buf *m, fallback: nf_log_buf_add(m, "MAC="); - if (dev->hard_header_len && skb_mac_header_was_set(skb) && - skb_mac_header_len(skb) != 0) { - const unsigned char *p = skb_mac_header(skb); - unsigned int i; + if (dev->hard_header_len && skb_mac_header_was_set(skb)) { + unsigned int mac_len; + + mac_len = min_t(unsigned int, skb_mac_header_len(skb), + dev->hard_header_len); + if (mac_len) { + const unsigned char *p = skb_mac_header(skb); + unsigned int i; - if (1) { nf_log_buf_add(m, "%02x", *p++); - for (i = 1; i < dev->hard_header_len; i++) + for (i = 1; i < mac_len; i++) nf_log_buf_add(m, ":%02x", *p++); } } -- 2.56.1