Commit 7643507f authored by Vishwanath Pai's avatar Vishwanath Pai Committed by Pablo Neira Ayuso

netfilter: xt_NFLOG: nflog-range does not truncate packets

li->u.ulog.copy_len is currently ignored by the kernel, we should truncate
the packet to either li->u.ulog.copy_len (if set) or copy_range before
sending it to userspace. 0 is a valid input for copy_len, so add a new
flag to indicate whether this was option was specified by the user or not.

Add two flags to indicate whether nflog-size/copy_len was set or not.
XT_NFLOG_F_COPY_LEN is for XT_NFLOG and NFLOG_F_COPY_LEN for nfnetlink_log

On the userspace side, this was initially represented by the option
nflog-range, this will be replaced by --nflog-size now. --nflog-range would
still exist but does not do anything.
Reported-by: default avatarJoe Dollard <jdollard@akamai.com>
Reviewed-by: default avatarJosh Hunt <johunt@akamai.com>
Signed-off-by: default avatarVishwanath Pai <vpai@akamai.com>
Signed-off-by: default avatarPablo Neira Ayuso <pablo@netfilter.org>
parent e1dbbc59
...@@ -12,6 +12,9 @@ ...@@ -12,6 +12,9 @@
#define NF_LOG_UID 0x08 /* Log UID owning local socket */ #define NF_LOG_UID 0x08 /* Log UID owning local socket */
#define NF_LOG_MASK 0x0f #define NF_LOG_MASK 0x0f
/* This flag indicates that copy_len field in nf_loginfo is set */
#define NF_LOG_F_COPY_LEN 0x1
enum nf_log_type { enum nf_log_type {
NF_LOG_TYPE_LOG = 0, NF_LOG_TYPE_LOG = 0,
NF_LOG_TYPE_ULOG, NF_LOG_TYPE_ULOG,
...@@ -22,9 +25,13 @@ struct nf_loginfo { ...@@ -22,9 +25,13 @@ struct nf_loginfo {
u_int8_t type; u_int8_t type;
union { union {
struct { struct {
/* copy_len will be used iff you set
* NF_LOG_F_COPY_LEN in flags
*/
u_int32_t copy_len; u_int32_t copy_len;
u_int16_t group; u_int16_t group;
u_int16_t qthreshold; u_int16_t qthreshold;
u_int16_t flags;
} ulog; } ulog;
struct { struct {
u_int8_t level; u_int8_t level;
......
...@@ -6,9 +6,13 @@ ...@@ -6,9 +6,13 @@
#define XT_NFLOG_DEFAULT_GROUP 0x1 #define XT_NFLOG_DEFAULT_GROUP 0x1
#define XT_NFLOG_DEFAULT_THRESHOLD 0 #define XT_NFLOG_DEFAULT_THRESHOLD 0
#define XT_NFLOG_MASK 0x0 #define XT_NFLOG_MASK 0x1
/* This flag indicates that 'len' field in xt_nflog_info is set*/
#define XT_NFLOG_F_COPY_LEN 0x1
struct xt_nflog_info { struct xt_nflog_info {
/* 'len' will be used iff you set XT_NFLOG_F_COPY_LEN in flags */
__u32 len; __u32 len;
__u16 group; __u16 group;
__u16 threshold; __u16 threshold;
......
...@@ -700,10 +700,13 @@ nfulnl_log_packet(struct net *net, ...@@ -700,10 +700,13 @@ nfulnl_log_packet(struct net *net,
break; break;
case NFULNL_COPY_PACKET: case NFULNL_COPY_PACKET:
if (inst->copy_range > skb->len)
data_len = skb->len;
else
data_len = inst->copy_range; data_len = inst->copy_range;
if ((li->u.ulog.flags & NF_LOG_F_COPY_LEN) &&
(li->u.ulog.copy_len < data_len))
data_len = li->u.ulog.copy_len;
if (data_len > skb->len)
data_len = skb->len;
size += nla_total_size(data_len); size += nla_total_size(data_len);
break; break;
......
...@@ -33,6 +33,9 @@ nflog_tg(struct sk_buff *skb, const struct xt_action_param *par) ...@@ -33,6 +33,9 @@ nflog_tg(struct sk_buff *skb, const struct xt_action_param *par)
li.u.ulog.group = info->group; li.u.ulog.group = info->group;
li.u.ulog.qthreshold = info->threshold; li.u.ulog.qthreshold = info->threshold;
if (info->flags & XT_NFLOG_F_COPY_LEN)
li.u.ulog.flags |= NF_LOG_F_COPY_LEN;
nfulnl_log_packet(net, par->family, par->hooknum, skb, par->in, nfulnl_log_packet(net, par->family, par->hooknum, skb, par->in,
par->out, &li, info->prefix); par->out, &li, info->prefix);
return XT_CONTINUE; return XT_CONTINUE;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment