GFS2: possible null pointer dereference fixup
PATCH 1/1 GFS2: possible null pointer dereference fixup
gfs2_alloc_get may fail so we have to check it to prevent NULL pointer dereference.
---
bmap.c | 6 +++++- dir.c | 10 +++++++--- eattr.c | 6 ++++++ inode.c | 7 ++++++- ops_address.c | 4 ++++ ops_inode.c | 11 ++++++++++- quota.c | 9 +++++++-- 7 files changed, 45 insertions(+), 8 deletions(-)
fs/gfs2/bmap.c +5 -1
@@ -808,6 +808,8 @@ static int do_grow(struct gfs2_inode *ipint error; al =gfs2_alloc_get (ip); +if (!al) +return -ENOMEM ; error =gfs2_quota_lock (ip,NO_QUOTA_CHANGE ,NO_QUOTA_CHANGE );if (error)
@@ -997,7 +999,9 @@ static int trunc_dealloc(struct gfs2_ino lblock = (size -1 ) >>GFS2_SB (&ip->i_inode)->sd_sb.sb_bsize_shift;find_metapath (ip, lblock, &mp); -gfs2_alloc_get (ip); + +if (!gfs2_alloc_get (ip)) +return -ENOMEM ; error =gfs2_quota_hold (ip,NO_QUOTA_CHANGE ,NO_QUOTA_CHANGE );if (error)
fs/gfs2/dir.c +7 -3
@@ -1870,11 +1870,14 @@ static int leaf_dealloc(struct gfs2_inodif (!ht)return -ENOMEM ; -gfs2_alloc_get (dip); +if (!gfs2_alloc_get (dip)) { + error = -ENOMEM ; + goto out; + } error =gfs2_quota_hold (dip,NO_QUOTA_CHANGE ,NO_QUOTA_CHANGE );if (error) - goto out; + goto out_put; error =gfs2_rindex_hold (sdp, &dip->i_alloc->al_ri_gh);if (error)
@@ -1952,8 +1955,9 @@ out_rlist:gfs2_glock_dq_uninit (&dip->i_alloc->al_ri_gh); out_qs:gfs2_quota_unhold (dip); -out: +out_put:gfs2_alloc_put (dip); +out:kfree (ht);return error; }
fs/gfs2/eattr.c +6 -0
@@ -321,6 +321,8 @@ static int ea_remove_unstuffed(struct gfint error; al =gfs2_alloc_get (ip); +if (!al) +return -ENOMEM ; error =gfs2_quota_hold (ip,NO_QUOTA_CHANGE ,NO_QUOTA_CHANGE );if (error)
@@ -684,6 +686,8 @@ static int ea_alloc_skeleton(struct gfs2int error; al =gfs2_alloc_get (ip); +if (!al) +return -ENOMEM ; error =gfs2_quota_lock (ip,NO_QUOTA_CHANGE ,NO_QUOTA_CHANGE );if (error)
@@ -1474,6 +1478,8 @@ int gfs2_ea_dealloc(struct gfs2_inode *iint error; al =gfs2_alloc_get (ip); +if (!al) +return -ENOMEM ; error =gfs2_quota_hold (ip,NO_QUOTA_CHANGE ,NO_QUOTA_CHANGE );if (error)
fs/gfs2/inode.c +6 -1
@@ -344,6 +344,8 @@ int gfs2_dinode_dealloc(struct gfs2_inod } al =gfs2_alloc_get (ip); +if (!al) +return -ENOMEM ; error =gfs2_quota_hold (ip,NO_QUOTA_CHANGE ,NO_QUOTA_CHANGE );if (error)
@@ -818,7 +820,8 @@ static int make_dinode(struct gfs2_inodeint error;munge_mode_uid_gid (dip, &mode, &uid, &gid); -gfs2_alloc_get (dip); +if (!gfs2_alloc_get (dip)) +return -ENOMEM ; error =gfs2_quota_lock (dip, uid, gid);if (error)
@@ -853,6 +856,8 @@ static int link_dinode(struct gfs2_inodeint error; al =gfs2_alloc_get (dip); +if (!al) +return -ENOMEM ; error =gfs2_quota_lock (dip,NO_QUOTA_CHANGE ,NO_QUOTA_CHANGE );if (error)
fs/gfs2/ops_address.c +4 -0
@@ -648,6 +648,10 @@ static int gfs2_write_begin(struct fileif (alloc_required) { al =gfs2_alloc_get (ip); +if (!al) { + error = -ENOMEM ; + goto out_unlock; + } error =gfs2_quota_lock (ip,NO_QUOTA_CHANGE ,NO_QUOTA_CHANGE );if (error)
fs/gfs2/ops_inode.c +10 -1
@@ -200,6 +200,10 @@ static int gfs2_link(struct dentry *old_if (alloc_required) {struct gfs2_alloc *al =gfs2_alloc_get (dip); +if (!al) { + error = -ENOMEM ; + goto out_gunlock; + } error =gfs2_quota_lock (dip,NO_QUOTA_CHANGE ,NO_QUOTA_CHANGE );if (error)
@@ -716,6 +720,10 @@ static int gfs2_rename(struct inode *odiif (alloc_required) {struct gfs2_alloc *al =gfs2_alloc_get (ndip); +if (!al) { + error = -ENOMEM ; + goto out_gunlock; + } error =gfs2_quota_lock (ndip,NO_QUOTA_CHANGE ,NO_QUOTA_CHANGE );if (error)
@@ -953,7 +961,8 @@ static int setattr_chown(struct inode *iif (!(attr->ia_valid &ATTR_GID ) || ogid == ngid) ogid = ngid =NO_QUOTA_CHANGE ; -gfs2_alloc_get (ip); +if (!gfs2_alloc_get (ip)) +return -ENOMEM ; error =gfs2_quota_lock (ip, nuid, ngid);if (error)
fs/gfs2/quota.c +7 -2
@@ -617,8 +617,9 @@ static int gfs2_adjust_quota(struct gfs2int err = -EIO ;if (gfs2_is_stuffed (ip)) { -struct gfs2_alloc *al =NULL ; - al =gfs2_alloc_get (ip); +struct gfs2_alloc *al =gfs2_alloc_get (ip); +if (!al) +return -ENOMEM ;/* just request 1 blk */ al->al_requested =1 ;gfs2_inplace_reserve (ip);
@@ -729,6 +730,10 @@ static int do_sync(unsigned int num_qd,if (nalloc) { al =gfs2_alloc_get (ip); +if (!al) { + error = -ENOMEM ; + goto out_gunlock; + } al->al_requested = nalloc * (data_blocks + ind_blocks);
Hi,
I had to adjust a couple of lines to make it apply to the GFS2 -nmw tree, but its now queued in that tree. Thanks,
Steve.
Quoted 212 lines · Cyrill Gorcunov
gfs2_alloc_getmay fail so we have to check it to prevent NULL pointer dereference.Signed-off-by Cyrill Gorcunov <[email protected]>---
bmap.c | 6 +++++- dir.c | 10 +++++++--- eattr.c | 6 ++++++ inode.c | 7 ++++++- ops_address.c | 4 ++++ ops_inode.c | 11 ++++++++++- quota.c | 9 +++++++-- 7 files changed, 45 insertions(+), 8 deletions(-)Index:
linux-2.6.git/fs/gfs2/bmap.c
===================================================================fs/gfs2/bmap.c +5
-1@@ -808,6 +808,8 @@ static int do_grow(struct gfs2_inode *ipint error; al =gfs2_alloc_get (ip); +if (!al) +return -ENOMEM ; error =gfs2_quota_lock (ip,NO_QUOTA_CHANGE ,NO_QUOTA_CHANGE );if (error)@@ -997,7 +999,9 @@ static int trunc_dealloc(struct gfs2_ino lblock = (size -1 ) >>GFS2_SB (&ip->i_inode)->sd_sb.sb_bsize_shift;find_metapath (ip, lblock, &mp); -gfs2_alloc_get (ip); + +if (!gfs2_alloc_get (ip)) +return -ENOMEM ; error =gfs2_quota_hold (ip,NO_QUOTA_CHANGE ,NO_QUOTA_CHANGE );if (error)Index:
linux-2.6.git/fs/gfs2/dir.c
===================================================================fs/gfs2/dir.c +7
-3@@ -1870,11 +1870,14 @@ static int leaf_dealloc(struct gfs2_inodif (!ht)return -ENOMEM ; -gfs2_alloc_get (dip); +if (!gfs2_alloc_get (dip)) { + error = -ENOMEM ; + goto out; + } error =gfs2_quota_hold (dip,NO_QUOTA_CHANGE ,NO_QUOTA_CHANGE );if (error) - goto out; + goto out_put; error =gfs2_rindex_hold (sdp, &dip->i_alloc->al_ri_gh);if (error)@@ -1952,8 +1955,9 @@ out_rlist:gfs2_glock_dq_uninit (&dip->i_alloc->al_ri_gh); out_qs:gfs2_quota_unhold (dip); -out: +out_put:gfs2_alloc_put (dip); +out:kfree (ht);return error; }Index:
linux-2.6.git/fs/gfs2/eattr.c
===================================================================fs/gfs2/eattr.c +6
-0@@ -321,6 +321,8 @@ static int ea_remove_unstuffed(struct gfint error; al =gfs2_alloc_get (ip); +if (!al) +return -ENOMEM ; error =gfs2_quota_hold (ip,NO_QUOTA_CHANGE ,NO_QUOTA_CHANGE );if (error)@@ -684,6 +686,8 @@ static int ea_alloc_skeleton(struct gfs2int error; al =gfs2_alloc_get (ip); +if (!al) +return -ENOMEM ; error =gfs2_quota_lock (ip,NO_QUOTA_CHANGE ,NO_QUOTA_CHANGE );if (error)@@ -1474,6 +1478,8 @@ int gfs2_ea_dealloc(struct gfs2_inode *iint error; al =gfs2_alloc_get (ip); +if (!al) +return -ENOMEM ; error =gfs2_quota_hold (ip,NO_QUOTA_CHANGE ,NO_QUOTA_CHANGE );if (error)Index:
linux-2.6.git/fs/gfs2/inode.c
===================================================================fs/gfs2/inode.c +6
-1@@ -344,6 +344,8 @@ int gfs2_dinode_dealloc(struct gfs2_inod } al =gfs2_alloc_get (ip); +if (!al) +return -ENOMEM ; error =gfs2_quota_hold (ip,NO_QUOTA_CHANGE ,NO_QUOTA_CHANGE );if (error)@@ -818,7 +820,8 @@ static int make_dinode(struct gfs2_inodeint error;munge_mode_uid_gid (dip, &mode, &uid, &gid); -gfs2_alloc_get (dip); +if (!gfs2_alloc_get (dip)) +return -ENOMEM ; error =gfs2_quota_lock (dip, uid, gid);if (error)@@ -853,6 +856,8 @@ static int link_dinode(struct gfs2_inodeint error; al =gfs2_alloc_get (dip); +if (!al) +return -ENOMEM ; error =gfs2_quota_lock (dip,NO_QUOTA_CHANGE ,NO_QUOTA_CHANGE );if (error)Index:
linux-2.6.git/fs/gfs2/ops_address.c
===================================================================fs/gfs2/ops_address.c +4
-0@@ -648,6 +648,10 @@ static int gfs2_write_begin(struct fileif (alloc_required) { al =gfs2_alloc_get (ip); +if (!al) { + error = -ENOMEM ; + goto out_unlock; + } error =gfs2_quota_lock (ip,NO_QUOTA_CHANGE ,NO_QUOTA_CHANGE );if (error)Index:
linux-2.6.git/fs/gfs2/ops_inode.c
===================================================================fs/gfs2/ops_inode.c +10
-1@@ -200,6 +200,10 @@ static int gfs2_link(struct dentry *old_if (alloc_required) {struct gfs2_alloc *al =gfs2_alloc_get (dip); +if (!al) { + error = -ENOMEM ; + goto out_gunlock; + } error =gfs2_quota_lock (dip,NO_QUOTA_CHANGE ,NO_QUOTA_CHANGE );if (error)@@ -716,6 +720,10 @@ static int gfs2_rename(struct inode *odiif (alloc_required) {struct gfs2_alloc *al =gfs2_alloc_get (ndip); +if (!al) { + error = -ENOMEM ; + goto out_gunlock; + } error =gfs2_quota_lock (ndip,NO_QUOTA_CHANGE ,NO_QUOTA_CHANGE );if (error)@@ -953,7 +961,8 @@ static int setattr_chown(struct inode *iif (!(attr->ia_valid &ATTR_GID ) || ogid == ngid) ogid = ngid =NO_QUOTA_CHANGE ; -gfs2_alloc_get (ip); +if (!gfs2_alloc_get (ip)) +return -ENOMEM ; error =gfs2_quota_lock (ip, nuid, ngid);if (error)Index:
linux-2.6.git/fs/gfs2/quota.c
===================================================================fs/gfs2/quota.c +7
-2@@ -617,8 +617,9 @@ static int gfs2_adjust_quota(struct gfs2int err = -EIO ;if (gfs2_is_stuffed (ip)) { -struct gfs2_alloc *al =NULL ; - al =gfs2_alloc_get (ip); +struct gfs2_alloc *al =gfs2_alloc_get (ip); +if (!al) +return -ENOMEM ;/* just request 1 blk */ al->al_requested =1 ;gfs2_inplace_reserve (ip);@@ -729,6 +730,10 @@ static int do_sync(unsigned int num_qd,if (nalloc) { al =gfs2_alloc_get (ip); +if (!al) { + error = -ENOMEM ; + goto out_gunlock; + } al->al_requested = nalloc * (data_blocks + ind_blocks);