Skip to content

Commit 182fe5a

Browse files
cyrillosswhiteho
authored andcommitted
[GFS2] possible null pointer dereference fixup
gfs2_alloc_get may fail so we have to check it to prevent NULL pointer dereference. Signed-off-by: Cyrill Gorcunov <gorcunov@gamil.com> Signed-off-by: Steven Whitehouse <swhiteho@redhat.com>
1 parent 1052849 commit 182fe5a

7 files changed

Lines changed: 44 additions & 8 deletions

File tree

‎fs/gfs2/bmap.c‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -900,6 +900,8 @@ static int do_grow(struct gfs2_inode *ip, u64 size)
900900
int error;
901901

902902
al = gfs2_alloc_get(ip);
903+
if (!al)
904+
return -ENOMEM;
903905

904906
error = gfs2_quota_lock(ip, NO_QUOTA_CHANGE, NO_QUOTA_CHANGE);
905907
if (error)
@@ -1081,7 +1083,8 @@ static int trunc_dealloc(struct gfs2_inode *ip, u64 size)
10811083
lblock = (size - 1) >> sdp->sd_sb.sb_bsize_shift;
10821084

10831085
find_metapath(sdp, lblock, &mp, ip->i_height);
1084-
gfs2_alloc_get(ip);
1086+
if (!gfs2_alloc_get(ip))
1087+
return -ENOMEM;
10851088

10861089
error = gfs2_quota_hold(ip, NO_QUOTA_CHANGE, NO_QUOTA_CHANGE);
10871090
if (error)

‎fs/gfs2/dir.c‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1868,11 +1868,14 @@ static int leaf_dealloc(struct gfs2_inode *dip, u32 index, u32 len,
18681868
if (!ht)
18691869
return -ENOMEM;
18701870

1871-
gfs2_alloc_get(dip);
1871+
if (!gfs2_alloc_get(dip)) {
1872+
error = -ENOMEM;
1873+
goto out;
1874+
}
18721875

18731876
error = gfs2_quota_hold(dip, NO_QUOTA_CHANGE, NO_QUOTA_CHANGE);
18741877
if (error)
1875-
goto out;
1878+
goto out_put;
18761879

18771880
error = gfs2_rindex_hold(sdp, &dip->i_alloc->al_ri_gh);
18781881
if (error)
@@ -1946,8 +1949,9 @@ static int leaf_dealloc(struct gfs2_inode *dip, u32 index, u32 len,
19461949
gfs2_glock_dq_uninit(&dip->i_alloc->al_ri_gh);
19471950
out_qs:
19481951
gfs2_quota_unhold(dip);
1949-
out:
1952+
out_put:
19501953
gfs2_alloc_put(dip);
1954+
out:
19511955
kfree(ht);
19521956
return error;
19531957
}

‎fs/gfs2/eattr.c‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,8 @@ static int ea_remove_unstuffed(struct gfs2_inode *ip, struct buffer_head *bh,
318318
int error;
319319

320320
al = gfs2_alloc_get(ip);
321+
if (!al)
322+
return -ENOMEM;
321323

322324
error = gfs2_quota_hold(ip, NO_QUOTA_CHANGE, NO_QUOTA_CHANGE);
323325
if (error)
@@ -681,6 +683,8 @@ static int ea_alloc_skeleton(struct gfs2_inode *ip, struct gfs2_ea_request *er,
681683
int error;
682684

683685
al = gfs2_alloc_get(ip);
686+
if (!al)
687+
return -ENOMEM;
684688

685689
error = gfs2_quota_lock(ip, NO_QUOTA_CHANGE, NO_QUOTA_CHANGE);
686690
if (error)
@@ -1464,6 +1468,8 @@ int gfs2_ea_dealloc(struct gfs2_inode *ip)
14641468
int error;
14651469

14661470
al = gfs2_alloc_get(ip);
1471+
if (!al)
1472+
return -ENOMEM;
14671473

14681474
error = gfs2_quota_hold(ip, NO_QUOTA_CHANGE, NO_QUOTA_CHANGE);
14691475
if (error)

‎fs/gfs2/inode.c‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,8 @@ int gfs2_dinode_dealloc(struct gfs2_inode *ip)
351351
}
352352

353353
al = gfs2_alloc_get(ip);
354+
if (!al)
355+
return -ENOMEM;
354356

355357
error = gfs2_quota_hold(ip, NO_QUOTA_CHANGE, NO_QUOTA_CHANGE);
356358
if (error)
@@ -825,7 +827,8 @@ static int make_dinode(struct gfs2_inode *dip, struct gfs2_glock *gl,
825827
int error;
826828

827829
munge_mode_uid_gid(dip, &mode, &uid, &gid);
828-
gfs2_alloc_get(dip);
830+
if (!gfs2_alloc_get(dip))
831+
return -ENOMEM;
829832

830833
error = gfs2_quota_lock(dip, uid, gid);
831834
if (error)
@@ -860,6 +863,8 @@ static int link_dinode(struct gfs2_inode *dip, const struct qstr *name,
860863
int error;
861864

862865
al = gfs2_alloc_get(dip);
866+
if (!al)
867+
return -ENOMEM;
863868

864869
error = gfs2_quota_lock(dip, NO_QUOTA_CHANGE, NO_QUOTA_CHANGE);
865870
if (error)

‎fs/gfs2/ops_address.c‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -649,6 +649,10 @@ static int gfs2_write_begin(struct file *file, struct address_space *mapping,
649649

650650
if (alloc_required) {
651651
al = gfs2_alloc_get(ip);
652+
if (!al) {
653+
error = -ENOMEM;
654+
goto out_unlock;
655+
}
652656

653657
error = gfs2_quota_lock(ip, NO_QUOTA_CHANGE, NO_QUOTA_CHANGE);
654658
if (error)

‎fs/gfs2/ops_inode.c‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,10 @@ static int gfs2_link(struct dentry *old_dentry, struct inode *dir,
200200

201201
if (alloc_required) {
202202
struct gfs2_alloc *al = gfs2_alloc_get(dip);
203+
if (!al) {
204+
error = -ENOMEM;
205+
goto out_gunlock;
206+
}
203207

204208
error = gfs2_quota_lock(dip, NO_QUOTA_CHANGE, NO_QUOTA_CHANGE);
205209
if (error)
@@ -716,6 +720,10 @@ static int gfs2_rename(struct inode *odir, struct dentry *odentry,
716720

717721
if (alloc_required) {
718722
struct gfs2_alloc *al = gfs2_alloc_get(ndip);
723+
if (!al) {
724+
error = -ENOMEM;
725+
goto out_gunlock;
726+
}
719727

720728
error = gfs2_quota_lock(ndip, NO_QUOTA_CHANGE, NO_QUOTA_CHANGE);
721729
if (error)
@@ -953,7 +961,8 @@ static int setattr_chown(struct inode *inode, struct iattr *attr)
953961
if (!(attr->ia_valid & ATTR_GID) || ogid == ngid)
954962
ogid = ngid = NO_QUOTA_CHANGE;
955963

956-
gfs2_alloc_get(ip);
964+
if (!gfs2_alloc_get(ip))
965+
return -ENOMEM;
957966

958967
error = gfs2_quota_lock(ip, nuid, ngid);
959968
if (error)

‎fs/gfs2/quota.c‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -617,8 +617,9 @@ static int gfs2_adjust_quota(struct gfs2_inode *ip, loff_t loc,
617617
int err = -EIO;
618618

619619
if (gfs2_is_stuffed(ip)) {
620-
struct gfs2_alloc *al = NULL;
621-
al = gfs2_alloc_get(ip);
620+
struct gfs2_alloc *al = gfs2_alloc_get(ip);
621+
if (!al)
622+
return -ENOMEM;
622623
/* just request 1 blk */
623624
al->al_requested = 1;
624625
gfs2_inplace_reserve(ip);
@@ -729,6 +730,10 @@ static int do_sync(unsigned int num_qd, struct gfs2_quota_data **qda)
729730

730731
if (nalloc) {
731732
al = gfs2_alloc_get(ip);
733+
if (!al) {
734+
error = -ENOMEM;
735+
goto out_gunlock;
736+
}
732737

733738
al->al_requested = nalloc * (data_blocks + ind_blocks);
734739

0 commit comments

Comments
 (0)