mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2024-09-05 18:39:59 +00:00
![Florian Westphal](/assets/img/avatar_default.png)
Harshit Mogalapalli says:
In ebt_do_table() function dereferencing 'private->hook_entry[hook]'
can lead to NULL pointer dereference. [..] Kernel panic:
general protection fault, probably for non-canonical address 0xdffffc0000000005: 0000 [#1] PREEMPT SMP KASAN
KASAN: null-ptr-deref in range [0x0000000000000028-0x000000000000002f]
[..]
RIP: 0010:ebt_do_table+0x1dc/0x1ce0
Code: 89 fa 48 c1 ea 03 80 3c 02 00 0f 85 5c 16 00 00 48 b8 00 00 00 00 00 fc ff df 49 8b 6c df 08 48 8d 7d 2c 48 89 fa 48 c1 ea 03 <0f> b6 14 02 48 89 f8 83 e0 07 83 c0 03 38 d0 7c 08 84 d2 0f 85 88
[..]
Call Trace:
nf_hook_slow+0xb1/0x170
__br_forward+0x289/0x730
maybe_deliver+0x24b/0x380
br_flood+0xc6/0x390
br_dev_xmit+0xa2e/0x12c0
For some reason ebtables rejects blobs that provide entry points that are
not supported by the table, but what it should instead reject is the
opposite: blobs that DO NOT provide an entry point supported by the table.
t->valid_hooks is the bitmask of hooks (input, forward ...) that will see
packets. Providing an entry point that is not support is harmless
(never called/used), but the inverse isn't: it results in a crash
because the ebtables traverser doesn't expect a NULL blob for a location
its receiving packets for.
Instead of fixing all the individual checks, do what iptables is doing and
reject all blobs that differ from the expected hooks.
Fixes: 1da177e4c3
("Linux-2.6.12-rc2")
Reported-by: Harshit Mogalapalli <harshit.m.mogalapalli@oracle.com>
Reported-by: syzkaller <syzkaller@googlegroups.com>
Signed-off-by: Florian Westphal <fw@strlen.de>
127 lines
4.1 KiB
C
127 lines
4.1 KiB
C
/* SPDX-License-Identifier: GPL-2.0 */
|
|
/*
|
|
* ebtables
|
|
*
|
|
* Authors:
|
|
* Bart De Schuymer <bdschuym@pandora.be>
|
|
*
|
|
* ebtables.c,v 2.0, April, 2002
|
|
*
|
|
* This code is strongly inspired by the iptables code which is
|
|
* Copyright (C) 1999 Paul `Rusty' Russell & Michael J. Neuling
|
|
*/
|
|
#ifndef __LINUX_BRIDGE_EFF_H
|
|
#define __LINUX_BRIDGE_EFF_H
|
|
|
|
#include <linux/if.h>
|
|
#include <linux/if_ether.h>
|
|
#include <uapi/linux/netfilter_bridge/ebtables.h>
|
|
|
|
struct ebt_match {
|
|
struct list_head list;
|
|
const char name[EBT_FUNCTION_MAXNAMELEN];
|
|
bool (*match)(const struct sk_buff *skb, const struct net_device *in,
|
|
const struct net_device *out, const struct xt_match *match,
|
|
const void *matchinfo, int offset, unsigned int protoff,
|
|
bool *hotdrop);
|
|
bool (*checkentry)(const char *table, const void *entry,
|
|
const struct xt_match *match, void *matchinfo,
|
|
unsigned int hook_mask);
|
|
void (*destroy)(const struct xt_match *match, void *matchinfo);
|
|
unsigned int matchsize;
|
|
u_int8_t revision;
|
|
u_int8_t family;
|
|
struct module *me;
|
|
};
|
|
|
|
struct ebt_watcher {
|
|
struct list_head list;
|
|
const char name[EBT_FUNCTION_MAXNAMELEN];
|
|
unsigned int (*target)(struct sk_buff *skb,
|
|
const struct net_device *in, const struct net_device *out,
|
|
unsigned int hook_num, const struct xt_target *target,
|
|
const void *targinfo);
|
|
bool (*checkentry)(const char *table, const void *entry,
|
|
const struct xt_target *target, void *targinfo,
|
|
unsigned int hook_mask);
|
|
void (*destroy)(const struct xt_target *target, void *targinfo);
|
|
unsigned int targetsize;
|
|
u_int8_t revision;
|
|
u_int8_t family;
|
|
struct module *me;
|
|
};
|
|
|
|
struct ebt_target {
|
|
struct list_head list;
|
|
const char name[EBT_FUNCTION_MAXNAMELEN];
|
|
/* returns one of the standard EBT_* verdicts */
|
|
unsigned int (*target)(struct sk_buff *skb,
|
|
const struct net_device *in, const struct net_device *out,
|
|
unsigned int hook_num, const struct xt_target *target,
|
|
const void *targinfo);
|
|
bool (*checkentry)(const char *table, const void *entry,
|
|
const struct xt_target *target, void *targinfo,
|
|
unsigned int hook_mask);
|
|
void (*destroy)(const struct xt_target *target, void *targinfo);
|
|
unsigned int targetsize;
|
|
u_int8_t revision;
|
|
u_int8_t family;
|
|
struct module *me;
|
|
};
|
|
|
|
/* used for jumping from and into user defined chains (udc) */
|
|
struct ebt_chainstack {
|
|
struct ebt_entries *chaininfo; /* pointer to chain data */
|
|
struct ebt_entry *e; /* pointer to entry data */
|
|
unsigned int n; /* n'th entry */
|
|
};
|
|
|
|
struct ebt_table_info {
|
|
/* total size of the entries */
|
|
unsigned int entries_size;
|
|
unsigned int nentries;
|
|
/* pointers to the start of the chains */
|
|
struct ebt_entries *hook_entry[NF_BR_NUMHOOKS];
|
|
/* room to maintain the stack used for jumping from and into udc */
|
|
struct ebt_chainstack **chainstack;
|
|
char *entries;
|
|
struct ebt_counter counters[] ____cacheline_aligned;
|
|
};
|
|
|
|
struct ebt_table {
|
|
struct list_head list;
|
|
char name[EBT_TABLE_MAXNAMELEN];
|
|
struct ebt_replace_kernel *table;
|
|
unsigned int valid_hooks;
|
|
rwlock_t lock;
|
|
/* the data used by the kernel */
|
|
struct ebt_table_info *private;
|
|
struct nf_hook_ops *ops;
|
|
struct module *me;
|
|
};
|
|
|
|
#define EBT_ALIGN(s) (((s) + (__alignof__(struct _xt_align)-1)) & \
|
|
~(__alignof__(struct _xt_align)-1))
|
|
|
|
extern int ebt_register_table(struct net *net,
|
|
const struct ebt_table *table,
|
|
const struct nf_hook_ops *ops);
|
|
extern void ebt_unregister_table(struct net *net, const char *tablename);
|
|
void ebt_unregister_table_pre_exit(struct net *net, const char *tablename);
|
|
extern unsigned int ebt_do_table(void *priv, struct sk_buff *skb,
|
|
const struct nf_hook_state *state);
|
|
|
|
/* True if the hook mask denotes that the rule is in a base chain,
|
|
* used in the check() functions */
|
|
#define BASE_CHAIN (par->hook_mask & (1 << NF_BR_NUMHOOKS))
|
|
/* Clear the bit in the hook mask that tells if the rule is on a base chain */
|
|
#define CLEAR_BASE_CHAIN_BIT (par->hook_mask &= ~(1 << NF_BR_NUMHOOKS))
|
|
|
|
static inline bool ebt_invalid_target(int target)
|
|
{
|
|
return (target < -NUM_STANDARD_TARGETS || target >= 0);
|
|
}
|
|
|
|
int ebt_register_template(const struct ebt_table *t, int(*table_init)(struct net *net));
|
|
void ebt_unregister_template(const struct ebt_table *t);
|
|
#endif
|