Skip to content
This repository was archived by the owner on Nov 8, 2023. It is now read-only.

Commit b20eacd

Browse files
committed
ANDROID: fix a bug in quota2
If quota is precisely equal to skb->len then a notification would not be sent due to immediately hitting 0. This fixes that, and takes the opportunity to slightly clean up the code and make quota behave more correctly for packet mode as well. Test: builds, net tests continue to pass Bug: 164336990 Signed-off-by: Maciej Żenczykowski <[email protected]> Change-Id: I78a11b48794496255513a6226c0469d809d7aa56
1 parent 29f30c5 commit b20eacd

File tree

1 file changed

+14
-15
lines changed

1 file changed

+14
-15
lines changed

net/netfilter/xt_quota2.c

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,8 @@ quota_mt2(const struct sk_buff *skb, struct xt_action_param *par)
306306
{
307307
struct xt_quota_mtinfo2 *q = (void *)par->matchinfo;
308308
struct xt_quota_counter *e = q->master;
309+
int charge = (q->flags & XT_QUOTA_PACKET) ? 1 : skb->len;
310+
bool no_change = q->flags & XT_QUOTA_NO_CHANGE;
309311
bool ret = q->flags & XT_QUOTA_INVERT;
310312

311313
spin_lock_bh(&e->lock);
@@ -314,24 +316,21 @@ quota_mt2(const struct sk_buff *skb, struct xt_action_param *par)
314316
* While no_change is pointless in "grow" mode, we will
315317
* implement it here simply to have a consistent behavior.
316318
*/
317-
if (!(q->flags & XT_QUOTA_NO_CHANGE)) {
318-
e->quota += (q->flags & XT_QUOTA_PACKET) ? 1 : skb->len;
319-
}
320-
ret = true;
319+
if (!no_change)
320+
e->quota += charge;
321+
ret = true; /* note: does not respect inversion (bug??) */
321322
} else {
322-
if (e->quota >= skb->len) {
323-
if (!(q->flags & XT_QUOTA_NO_CHANGE))
324-
e->quota -= (q->flags & XT_QUOTA_PACKET) ? 1 : skb->len;
323+
if (e->quota > charge) {
324+
if (!no_change)
325+
e->quota -= charge;
325326
ret = !ret;
326-
} else {
327+
} else if (e->quota) {
327328
/* We are transitioning, log that fact. */
328-
if (e->quota) {
329-
quota2_log(xt_hooknum(par),
330-
skb,
331-
xt_in(par),
332-
xt_out(par),
333-
q->name);
334-
}
329+
quota2_log(xt_hooknum(par),
330+
skb,
331+
xt_in(par),
332+
xt_out(par),
333+
q->name);
335334
/* we do not allow even small packets from now on */
336335
e->quota = 0;
337336
}

0 commit comments

Comments
 (0)