Skip to contentSkip to conversation

fs: gfs2: possible null-pointer dereferences in gfs2_rgrp_bh_get()

BUG Jia-Ju Bai 2 participants 3 messages Jul 24, 2019

lore
Share & tools
lore

Jia-Ju Bai

author
#0 lore raw

In gfs2_rgrp_bh_get, there is an if statement on line 1191 to check whether "rgd->rd_bits[0].bi_bh" is NULL.
When "rgd->rd_bits[0].bi_bh" is NULL, it is used on line 1216:
??? gfs2_rgrp_in(rgd, (rgd->rd_bits[0].bi_bh)->b_data);
and on line 1225:
??? gfs2_rgrp_ondisk2lvb(..., rgd->rd_bits[0].bi_bh->b_data);
and on line 1228:
??? if (!gfs2_rgrp_lvb_valid(rgd))

Note that in gfs2_rgrp_lvb_valid(rgd), there is a statement on line 1114:
??? struct gfs2_rgrp *str = (struct gfs2_rgrp
*)rgd->rd_bits[0].bi_bh->b_data;

Thus, possible null-pointer dereferences may occur.

These bugs are found by a static analysis tool STCheck written by us. I do not know how to correctly fix these bugs, so I only report bugs.

Best wishes,
Jia-Ju Bai

#1 lore raw

Hi,

Quoted 2 lines · Jia-Ju Bai

In gfs2_rgrp_bh_get, there is an if statement on line 1191 to check whether "rgd->rd_bits[0].bi_bh" is NULL.

That is how we detect whether the rgrp has already been read in, so the function is skipped in the case that we've already read in the rgrp.

Quoted 2 lines

When "rgd->rd_bits[0].bi_bh" is NULL, it is used on line 1216:
??? gfs2_rgrp_in(rgd, (rgd->rd_bits[0].bi_bh)->b_data);

No it isn't. See line 1196 where bi_bh is set, and where we also bail out (line 1198) in case it has not been set.

Quoted 9 lines

and on line 1225:
??? gfs2_rgrp_ondisk2lvb(..., rgd->rd_bits[0].bi_bh->b_data); and on line 1228:
??? if (!gfs2_rgrp_lvb_valid(rgd))

Note that in gfs2_rgrp_lvb_valid(rgd), there is a statement on line 1114:
??? struct gfs2_rgrp *str = (struct gfs2_rgrp *)rgd->rd_bits[0].bi_bh->b_data;

Quoted 9 lines

Thus, possible null-pointer dereferences may occur.

These bugs are found by a static analysis tool STCheck written by us. I do not know how to correctly fix these bugs, so I only report bugs.

Best wishes,
Jia-Ju Bai

So I'm not seeing how there can be a NULL deref in those later lines. I think this is another false positive,

Steve.

author
#2 lore raw

Thanks for the reply :)

Quoted 10 lines · Steven Whitehouse

Hi,

Quoted 2 lines · Jia-Ju Bai

In gfs2_rgrp_bh_get, there is an if statement on line 1191 to check whether "rgd->rd_bits[0].bi_bh" is NULL.

That is how we detect whether the rgrp has already been read in, so the function is skipped in the case that we've already read in the rgrp.

Quoted 6 lines
Quoted 2 lines

When "rgd->rd_bits[0].bi_bh" is NULL, it is used on line 1216:
??? gfs2_rgrp_in(rgd, (rgd->rd_bits[0].bi_bh)->b_data);

No it isn't. See line 1196 where bi_bh is set, and where we also bail out (line 1198) in case it has not been set.

I overlooked the operation on line 1196...
Thanks for the pointer, I am sorry for the false report...

Best wishes,
Jia-Ju Bai