"ds" gets dereferenced after a kfree in the debug output. I just
moved the free down a line.
Signed-off-by: Dan Carpenter <[email protected]>
diff --git a/fs/nfs/nfs4filelayoutdev.c b/fs/nfs/nfs4filelayoutdev.c
index 77c171e..c63bbce 100644
--- a/fs/nfs/nfs4filelayoutdev.c
+++ b/fs/nfs/nfs4filelayoutdev.c
@@ -362,11 +362,11 @@ nfs4_pnfs_ds_add(struct list_head *dsaddrs, gfp_t gfp_flags)
__func__, tmp_ds->ds_remotestr, remotestr);
}
kfree(remotestr);
- kfree(ds);
atomic_inc(&tmp_ds->ds_count);
dprintk("%s data server %s found, inc'ed ds_count to %d\n",
__func__, ds->ds_remotestr,
atomic_read(&tmp_ds->ds_count));
+ kfree(ds);
ds = tmp_ds;
}
spin_unlock(&nfs4_ds_cache_lock);
Oops, good catch!
Actually, we can leave the kfree() where it is. Using ds->ds_remotestr in the dprintk is a typo - It should be tmp_ds->ds_remotestr.
-dros
On Jun 8, 2011, at 2:43 AM, Dan Carpenter wrote:
> "ds" gets dereferenced after a kfree in the debug output. I just
> moved the free down a line.
>
> Signed-off-by: Dan Carpenter <[email protected]>
>
> diff --git a/fs/nfs/nfs4filelayoutdev.c b/fs/nfs/nfs4filelayoutdev.c
> index 77c171e..c63bbce 100644
> --- a/fs/nfs/nfs4filelayoutdev.c
> +++ b/fs/nfs/nfs4filelayoutdev.c
> @@ -362,11 +362,11 @@ nfs4_pnfs_ds_add(struct list_head *dsaddrs, gfp_t gfp_flags)
> __func__, tmp_ds->ds_remotestr, remotestr);
> }
> kfree(remotestr);
> - kfree(ds);
> atomic_inc(&tmp_ds->ds_count);
> dprintk("%s data server %s found, inc'ed ds_count to %d\n",
> __func__, ds->ds_remotestr,
> atomic_read(&tmp_ds->ds_count));
> + kfree(ds);
> ds = tmp_ds;
> }
> spin_unlock(&nfs4_ds_cache_lock);
> --
> To unsubscribe from this list: send the line "unsubscribe linux-nfs" in
> the body of a message to [email protected]
> More majordomo info at http://vger.kernel.org/majordomo-info.html
"tmp_ds" was intended here instead of "ds". Also "ds" was already
freed.
Signed-off-by: Dan Carpenter <[email protected]>
---
v1 fixed the user-after-free but left the message incorrect.
diff --git a/fs/nfs/nfs4filelayoutdev.c b/fs/nfs/nfs4filelayoutdev.c
index 77c171e..ed388aa 100644
--- a/fs/nfs/nfs4filelayoutdev.c
+++ b/fs/nfs/nfs4filelayoutdev.c
@@ -365,7 +365,7 @@ nfs4_pnfs_ds_add(struct list_head *dsaddrs, gfp_t gfp_flags)
kfree(ds);
atomic_inc(&tmp_ds->ds_count);
dprintk("%s data server %s found, inc'ed ds_count to %d\n",
- __func__, ds->ds_remotestr,
+ __func__, tmp_ds->ds_remotestr,
atomic_read(&tmp_ds->ds_count));
ds = tmp_ds;
}