gfs2: Fix possible fs name overflows
authorBob Peterson <rpeterso@redhat.com>
Tue, 13 Aug 2019 13:25:15 +0000 (09:25 -0400)
committerAndreas Gruenbacher <agruenba@redhat.com>
Tue, 3 Sep 2019 07:42:41 +0000 (09:42 +0200)
This patch fixes three places in which temporary character buffers
could overflow due to the addition of the file system id from patch
3792ce973f07. Thanks to Dan Carpenter for pointing it out.

Signed-off-by: Bob Peterson <rpeterso@redhat.com>
Signed-off-by: Andreas Gruenbacher <agruenba@redhat.com>
fs/gfs2/glock.c
fs/gfs2/rgrp.c
fs/gfs2/util.c

index e23fb8b7b020ef56f6bde4d93af0c48daa3a2005..a27dbd3dec011f6de5c202293f32dc91c3dceaf1 100644 (file)
@@ -1788,8 +1788,8 @@ void gfs2_dump_glock(struct seq_file *seq, struct gfs2_glock *gl, bool fsid)
        unsigned long long dtime;
        const struct gfs2_holder *gh;
        char gflags_buf[32];
-       char fs_id_buf[GFS2_FSNAME_LEN + 3 * sizeof(int) + 2];
        struct gfs2_sbd *sdp = gl->gl_name.ln_sbd;
+       char fs_id_buf[sizeof(sdp->sd_fsname) + 7];
 
        memset(fs_id_buf, 0, sizeof(fs_id_buf));
        if (fsid && sdp) /* safety precaution */
index 49ac0a5e74ea7d06fb951d3a7bc02338db3097b8..2466bb44a23c510b55f7955affad73b74e38c34a 100644 (file)
@@ -2285,7 +2285,7 @@ void gfs2_rgrp_dump(struct seq_file *seq, struct gfs2_glock *gl,
 static void gfs2_rgrp_error(struct gfs2_rgrpd *rgd)
 {
        struct gfs2_sbd *sdp = rgd->rd_sbd;
-       char fs_id_buf[GFS2_FSNAME_LEN + 3 * sizeof(int) + 2];
+       char fs_id_buf[sizeof(sdp->sd_fsname) + 7];
 
        fs_warn(sdp, "rgrp %llu has an error, marking it readonly until umount\n",
                (unsigned long long)rgd->rd_addr);
index 83f6c582773a5aa2188285ed27c6779037ad5ee3..c45159133d8eef8a088ae38f394fb6a0e660fc8d 100644 (file)
@@ -178,7 +178,7 @@ int gfs2_consist_rgrpd_i(struct gfs2_rgrpd *rgd, int cluster_wide,
                         const char *function, char *file, unsigned int line)
 {
        struct gfs2_sbd *sdp = rgd->rd_sbd;
-       char fs_id_buf[GFS2_FSNAME_LEN + 3 * sizeof(int) + 2];
+       char fs_id_buf[sizeof(sdp->sd_fsname) + 7];
        int rv;
 
        sprintf(fs_id_buf, "fsid=%s: ", sdp->sd_fsname);