Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

gfs2: Add missing else in trans_add_meta/data

This patch fixes a timing window that causes a segfault.
The problem is that bd can remain NULL throughout the function
and then reference that NULL pointer if the bh->b_private starts
out NULL, then someone sets it to non-NULL inside the locking.
In that case, bd still needs to be set.

Signed-off-by: Bob Peterson <rpeterso@redhat.com>

+4
+4
fs/gfs2/trans.c
··· 176 176 unlock_buffer(bh); 177 177 if (bh->b_private == NULL) 178 178 bd = gfs2_alloc_bufdata(gl, bh, &gfs2_databuf_lops); 179 + else 180 + bd = bh->b_private; 179 181 lock_buffer(bh); 180 182 gfs2_log_lock(sdp); 181 183 } ··· 238 236 lock_page(bh->b_page); 239 237 if (bh->b_private == NULL) 240 238 bd = gfs2_alloc_bufdata(gl, bh, &gfs2_buf_lops); 239 + else 240 + bd = bh->b_private; 241 241 unlock_page(bh->b_page); 242 242 lock_buffer(bh); 243 243 gfs2_log_lock(sdp);