]> err.no Git - linux-2.6/blobdiff - net/netfilter/nf_conntrack_extend.c
netfilter: fix string extension for case insensitive pattern matching
[linux-2.6] / net / netfilter / nf_conntrack_extend.c
index bcc19fa4ed1e07ab4277f7c02c933235cd0dc261..3469bc71a385eacb66b2099c334833469ec889cf 100644 (file)
@@ -59,12 +59,19 @@ nf_ct_ext_create(struct nf_ct_ext **ext, enum nf_ct_ext_id id, gfp_t gfp)
        if (!*ext)
                return NULL;
 
+       INIT_RCU_HEAD(&(*ext)->rcu);
        (*ext)->offset[id] = off;
        (*ext)->len = len;
 
        return (void *)(*ext) + off;
 }
 
+static void __nf_ct_ext_free_rcu(struct rcu_head *head)
+{
+       struct nf_ct_ext *ext = container_of(head, struct nf_ct_ext, rcu);
+       kfree(ext);
+}
+
 void *__nf_ct_ext_add(struct nf_conn *ct, enum nf_ct_ext_id id, gfp_t gfp)
 {
        struct nf_ct_ext *new;
@@ -88,13 +95,11 @@ void *__nf_ct_ext_add(struct nf_conn *ct, enum nf_ct_ext_id id, gfp_t gfp)
        newlen = newoff + t->len;
        rcu_read_unlock();
 
-       if (newlen >= ksize(ct->ext)) {
-               new = kmalloc(newlen, gfp);
-               if (!new)
-                       return NULL;
-
-               memcpy(new, ct->ext, ct->ext->len);
+       new = krealloc(ct->ext, newlen, gfp);
+       if (!new)
+               return NULL;
 
+       if (new != ct->ext) {
                for (i = 0; i < NF_CT_EXT_NUM; i++) {
                        if (!nf_ct_ext_exist(ct, i))
                                continue;
@@ -106,7 +111,7 @@ void *__nf_ct_ext_add(struct nf_conn *ct, enum nf_ct_ext_id id, gfp_t gfp)
                                        (void *)ct->ext + ct->ext->offset[i]);
                        rcu_read_unlock();
                }
-               kfree(ct->ext);
+               call_rcu(&ct->ext->rcu, __nf_ct_ext_free_rcu);
                ct->ext = new;
        }