netfilter: nfnetlink_acct: avoid using NFACCT_F_OVERQUOTA with bit helper functions
Bit helper functions were used for manipulation with NFACCT_F_OVERQUOTA, but they are accepting pit position, but not a bit mask. As a result not a third bit for NFACCT_F_OVERQUOTA was set, but forth. Such behaviour was dangarous and could lead to unexpected overquota report result. Signed-off-by: Alexey Perevalov <a.perevalov@samsung.com> Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
This commit is contained in:
parent
d24675cb1f
commit
b6d0468804
|
@ -41,6 +41,7 @@ struct nf_acct {
|
||||||
};
|
};
|
||||||
|
|
||||||
#define NFACCT_F_QUOTA (NFACCT_F_QUOTA_PKTS | NFACCT_F_QUOTA_BYTES)
|
#define NFACCT_F_QUOTA (NFACCT_F_QUOTA_PKTS | NFACCT_F_QUOTA_BYTES)
|
||||||
|
#define NFACCT_OVERQUOTA_BIT 2 /* NFACCT_F_OVERQUOTA */
|
||||||
|
|
||||||
static int
|
static int
|
||||||
nfnl_acct_new(struct sock *nfnl, struct sk_buff *skb,
|
nfnl_acct_new(struct sock *nfnl, struct sk_buff *skb,
|
||||||
|
@ -77,7 +78,8 @@ nfnl_acct_new(struct sock *nfnl, struct sk_buff *skb,
|
||||||
smp_mb__before_atomic();
|
smp_mb__before_atomic();
|
||||||
/* reset overquota flag if quota is enabled. */
|
/* reset overquota flag if quota is enabled. */
|
||||||
if ((matching->flags & NFACCT_F_QUOTA))
|
if ((matching->flags & NFACCT_F_QUOTA))
|
||||||
clear_bit(NFACCT_F_OVERQUOTA, &matching->flags);
|
clear_bit(NFACCT_OVERQUOTA_BIT,
|
||||||
|
&matching->flags);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
return -EBUSY;
|
return -EBUSY;
|
||||||
|
@ -150,7 +152,7 @@ nfnl_acct_fill_info(struct sk_buff *skb, u32 portid, u32 seq, u32 type,
|
||||||
bytes = atomic64_xchg(&acct->bytes, 0);
|
bytes = atomic64_xchg(&acct->bytes, 0);
|
||||||
smp_mb__before_atomic();
|
smp_mb__before_atomic();
|
||||||
if (acct->flags & NFACCT_F_QUOTA)
|
if (acct->flags & NFACCT_F_QUOTA)
|
||||||
clear_bit(NFACCT_F_OVERQUOTA, &acct->flags);
|
clear_bit(NFACCT_OVERQUOTA_BIT, &acct->flags);
|
||||||
} else {
|
} else {
|
||||||
pkts = atomic64_read(&acct->pkts);
|
pkts = atomic64_read(&acct->pkts);
|
||||||
bytes = atomic64_read(&acct->bytes);
|
bytes = atomic64_read(&acct->bytes);
|
||||||
|
@ -414,7 +416,7 @@ int nfnl_acct_overquota(const struct sk_buff *skb, struct nf_acct *nfacct)
|
||||||
ret = now > *quota;
|
ret = now > *quota;
|
||||||
|
|
||||||
if (now >= *quota &&
|
if (now >= *quota &&
|
||||||
!test_and_set_bit(NFACCT_F_OVERQUOTA, &nfacct->flags)) {
|
!test_and_set_bit(NFACCT_OVERQUOTA_BIT, &nfacct->flags)) {
|
||||||
nfnl_overquota_report(nfacct);
|
nfnl_overquota_report(nfacct);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue