Skip to content

Commit

Permalink
net/garp: avoid infinite loop if attribute already exists
Browse files Browse the repository at this point in the history
An infinite loop occurred if garp_attr_create was called with the values
of an existing attribute. This might happen if a previous leave request
for the attribute has not yet been followed by a PDU transmission (or,
if the application previously issued a join request for the attribute
and is now issuing another one, without having issued a leave request).

If garp_attr_create finds an existing attribute having the same values,
return the address to it. Its state will then get updated (i.e., if it
was in a leaving state, it will move into a non-leaving state and not
get deleted during the next PDU transmission).

To accomplish this fix, collapse garp_attr_insert into garp_attr_create
(which is its only caller).

Thanks to Jorge Boncompte [DTI2] <[email protected]> for contributing to
this fix.

Signed-off-by: David Ward <[email protected]>
Acked-by: Jorge Boncompte [DTI2] <[email protected]>
Signed-off-by: David S. Miller <[email protected]>
  • Loading branch information
dpward authored and davem330 committed Apr 1, 2012
1 parent 54f5ffb commit 6737856
Showing 1 changed file with 10 additions and 12 deletions.
22 changes: 10 additions & 12 deletions net/802/garp.c
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,8 @@ static struct garp_attr *garp_attr_lookup(const struct garp_applicant *app,
return NULL;
}

static void garp_attr_insert(struct garp_applicant *app, struct garp_attr *new)
static struct garp_attr *garp_attr_create(struct garp_applicant *app,
const void *data, u8 len, u8 type)
{
struct rb_node *parent = NULL, **p = &app->gid.rb_node;
struct garp_attr *attr;
Expand All @@ -176,29 +177,26 @@ static void garp_attr_insert(struct garp_applicant *app, struct garp_attr *new)
while (*p) {
parent = *p;
attr = rb_entry(parent, struct garp_attr, node);
d = garp_attr_cmp(attr, new->data, new->dlen, new->type);
d = garp_attr_cmp(attr, data, len, type);
if (d < 0)
p = &parent->rb_left;
else if (d > 0)
p = &parent->rb_right;
else {
/* The attribute already exists; re-use it. */
return attr;
}
}
rb_link_node(&new->node, parent, p);
rb_insert_color(&new->node, &app->gid);
}

static struct garp_attr *garp_attr_create(struct garp_applicant *app,
const void *data, u8 len, u8 type)
{
struct garp_attr *attr;

attr = kmalloc(sizeof(*attr) + len, GFP_ATOMIC);
if (!attr)
return attr;
attr->state = GARP_APPLICANT_VO;
attr->type = type;
attr->dlen = len;
memcpy(attr->data, data, len);
garp_attr_insert(app, attr);

rb_link_node(&attr->node, parent, p);
rb_insert_color(&attr->node, &app->gid);
return attr;
}

Expand Down

0 comments on commit 6737856

Please sign in to comment.