提交 779994fa 编写于 作者: G Gao Feng 提交者: Pablo Neira Ayuso

netfilter: log: Check param to avoid overflow in nf_log_set

The nf_log_set is an interface function, so it should do the strict sanity
check of parameters. Convert the return value of nf_log_set as int instead
of void. When the pf is invalid, return -EOPNOTSUPP.
Signed-off-by: NGao Feng <fgao@ikuai8.com>
Signed-off-by: NPablo Neira Ayuso <pablo@netfilter.org>
上级 3cb27991
...@@ -60,8 +60,7 @@ struct nf_logger { ...@@ -60,8 +60,7 @@ struct nf_logger {
int nf_log_register(u_int8_t pf, struct nf_logger *logger); int nf_log_register(u_int8_t pf, struct nf_logger *logger);
void nf_log_unregister(struct nf_logger *logger); void nf_log_unregister(struct nf_logger *logger);
void nf_log_set(struct net *net, u_int8_t pf, int nf_log_set(struct net *net, u_int8_t pf, const struct nf_logger *logger);
const struct nf_logger *logger);
void nf_log_unset(struct net *net, const struct nf_logger *logger); void nf_log_unset(struct net *net, const struct nf_logger *logger);
int nf_log_bind_pf(struct net *net, u_int8_t pf, int nf_log_bind_pf(struct net *net, u_int8_t pf,
......
...@@ -50,8 +50,7 @@ static struct nf_logger nf_bridge_logger __read_mostly = { ...@@ -50,8 +50,7 @@ static struct nf_logger nf_bridge_logger __read_mostly = {
static int __net_init nf_log_bridge_net_init(struct net *net) static int __net_init nf_log_bridge_net_init(struct net *net)
{ {
nf_log_set(net, NFPROTO_BRIDGE, &nf_bridge_logger); return nf_log_set(net, NFPROTO_BRIDGE, &nf_bridge_logger);
return 0;
} }
static void __net_exit nf_log_bridge_net_exit(struct net *net) static void __net_exit nf_log_bridge_net_exit(struct net *net)
......
...@@ -111,8 +111,7 @@ static struct nf_logger nf_arp_logger __read_mostly = { ...@@ -111,8 +111,7 @@ static struct nf_logger nf_arp_logger __read_mostly = {
static int __net_init nf_log_arp_net_init(struct net *net) static int __net_init nf_log_arp_net_init(struct net *net)
{ {
nf_log_set(net, NFPROTO_ARP, &nf_arp_logger); return nf_log_set(net, NFPROTO_ARP, &nf_arp_logger);
return 0;
} }
static void __net_exit nf_log_arp_net_exit(struct net *net) static void __net_exit nf_log_arp_net_exit(struct net *net)
......
...@@ -347,8 +347,7 @@ static struct nf_logger nf_ip_logger __read_mostly = { ...@@ -347,8 +347,7 @@ static struct nf_logger nf_ip_logger __read_mostly = {
static int __net_init nf_log_ipv4_net_init(struct net *net) static int __net_init nf_log_ipv4_net_init(struct net *net)
{ {
nf_log_set(net, NFPROTO_IPV4, &nf_ip_logger); return nf_log_set(net, NFPROTO_IPV4, &nf_ip_logger);
return 0;
} }
static void __net_exit nf_log_ipv4_net_exit(struct net *net) static void __net_exit nf_log_ipv4_net_exit(struct net *net)
......
...@@ -379,8 +379,7 @@ static struct nf_logger nf_ip6_logger __read_mostly = { ...@@ -379,8 +379,7 @@ static struct nf_logger nf_ip6_logger __read_mostly = {
static int __net_init nf_log_ipv6_net_init(struct net *net) static int __net_init nf_log_ipv6_net_init(struct net *net)
{ {
nf_log_set(net, NFPROTO_IPV6, &nf_ip6_logger); return nf_log_set(net, NFPROTO_IPV6, &nf_ip6_logger);
return 0;
} }
static void __net_exit nf_log_ipv6_net_exit(struct net *net) static void __net_exit nf_log_ipv6_net_exit(struct net *net)
......
...@@ -39,12 +39,12 @@ static struct nf_logger *__find_logger(int pf, const char *str_logger) ...@@ -39,12 +39,12 @@ static struct nf_logger *__find_logger(int pf, const char *str_logger)
return NULL; return NULL;
} }
void nf_log_set(struct net *net, u_int8_t pf, const struct nf_logger *logger) int nf_log_set(struct net *net, u_int8_t pf, const struct nf_logger *logger)
{ {
const struct nf_logger *log; const struct nf_logger *log;
if (pf == NFPROTO_UNSPEC) if (pf == NFPROTO_UNSPEC || pf >= ARRAY_SIZE(net->nf.nf_loggers))
return; return -EOPNOTSUPP;
mutex_lock(&nf_log_mutex); mutex_lock(&nf_log_mutex);
log = nft_log_dereference(net->nf.nf_loggers[pf]); log = nft_log_dereference(net->nf.nf_loggers[pf]);
...@@ -52,6 +52,8 @@ void nf_log_set(struct net *net, u_int8_t pf, const struct nf_logger *logger) ...@@ -52,6 +52,8 @@ void nf_log_set(struct net *net, u_int8_t pf, const struct nf_logger *logger)
rcu_assign_pointer(net->nf.nf_loggers[pf], logger); rcu_assign_pointer(net->nf.nf_loggers[pf], logger);
mutex_unlock(&nf_log_mutex); mutex_unlock(&nf_log_mutex);
return 0;
} }
EXPORT_SYMBOL(nf_log_set); EXPORT_SYMBOL(nf_log_set);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册