gfs2-utils: RHEL7 - mkfs.gfs2: Terminate lockproto and locktable strings explicitly
by Andrew Price
Gitweb: http://git.fedorahosted.org/git/?p=gfs2-utils.git;a=commitdiff;h=29daf413...
Commit: 29daf41307107693525caa692f9e74639757f650
Parent: c883c0cef51b116fb6c20bfdfe39542a37e45d5a
Author: Andrew Price <anprice(a)redhat.com>
AuthorDate: Mon Oct 6 14:22:16 2014 +0100
Committer: Andrew Price <anprice(a)redhat.com>
CommitterDate: Wed Apr 1 16:51:34 2015 +0100
mkfs.gfs2: Terminate lockproto and locktable strings explicitly
Although the length of the lockproto and locktable options are checked
in test_locking() already, coverity still complains about our use of
strcpy here, and it can't hurt to be a bit more defensive in our string
handling so switch to strncpy and terminate the strings explicitly.
Signed-off-by: Andrew Price <anprice(a)redhat.com>
---
gfs2/mkfs/main_mkfs.c | 6 ++++--
1 files changed, 4 insertions(+), 2 deletions(-)
diff --git a/gfs2/mkfs/main_mkfs.c b/gfs2/mkfs/main_mkfs.c
index f4b8fe6..282878d 100644
--- a/gfs2/mkfs/main_mkfs.c
+++ b/gfs2/mkfs/main_mkfs.c
@@ -966,8 +966,10 @@ void main_mkfs(int argc, char *argv[])
build_root(&sbd);
sb.sb_root_dir = sbd.md.rooti->i_di.di_num;
- strcpy(sb.sb_lockproto, opts.lockproto);
- strcpy(sb.sb_locktable, opts.locktable);
+ strncpy(sb.sb_lockproto, opts.lockproto, GFS2_LOCKNAME_LEN);
+ strncpy(sb.sb_locktable, opts.locktable, GFS2_LOCKNAME_LEN);
+ sb.sb_lockproto[GFS2_LOCKNAME_LEN - 1] = '\0';
+ sb.sb_locktable[GFS2_LOCKNAME_LEN - 1] = '\0';
do_init_inum(&sbd);
do_init_statfs(&sbd);
9 years
gfs2-utils: RHEL7 - fsck.gfs2: Remove dead code from scan_inode_list
by Andrew Price
Gitweb: http://git.fedorahosted.org/git/?p=gfs2-utils.git;a=commitdiff;h=c883c0ce...
Commit: c883c0cef51b116fb6c20bfdfe39542a37e45d5a
Parent: 5f329b5b8a35ca56fe70cb4fc067e4aff34b1b94
Author: Andrew Price <anprice(a)redhat.com>
AuthorDate: Mon Oct 6 13:41:17 2014 +0100
Committer: Andrew Price <anprice(a)redhat.com>
CommitterDate: Wed Apr 1 16:51:34 2015 +0100
fsck.gfs2: Remove dead code from scan_inode_list
Spotted by coverity: At condition "ii = (struct inode_info *)tmp", the
value of "ii" cannot be "NULL".
In other words, tmp cannot be NULL here because the loop would have
ended in that case. Remove the NULL check and the overly excited error
message.
Signed-off-by: Andrew Price <anprice(a)redhat.com>
---
gfs2/fsck/pass4.c | 5 +----
1 files changed, 1 insertions(+), 4 deletions(-)
diff --git a/gfs2/fsck/pass4.c b/gfs2/fsck/pass4.c
index f0c13fc..324ea9f 100644
--- a/gfs2/fsck/pass4.c
+++ b/gfs2/fsck/pass4.c
@@ -58,10 +58,7 @@ static int scan_inode_list(struct gfs2_sbd *sdp) {
if (lf_dip && lf_as.as_blocks == 0)
astate_save(lf_dip, &lf_as);
next = osi_next(tmp);
- if (!(ii = (struct inode_info *)tmp)) {
- log_crit( _("osi_tree broken in scan_info_list!!\n"));
- exit(FSCK_ERROR);
- }
+ ii = (struct inode_info *)tmp;
/* Don't check reference counts on the special gfs files */
if (sdp->gfs1 &&
((ii->di_num.no_addr == sdp->md.riinode->i_di.di_num.no_addr) ||
9 years
gfs2-utils: RHEL7 - libgfs2: Fix check for O_RDONLY
by Andrew Price
Gitweb: http://git.fedorahosted.org/git/?p=gfs2-utils.git;a=commitdiff;h=5f329b5b...
Commit: 5f329b5b8a35ca56fe70cb4fc067e4aff34b1b94
Parent: 7e3a8b6da97574d086aaecb94a08596925b82d41
Author: Andrew Price <anprice(a)redhat.com>
AuthorDate: Mon Oct 6 12:44:49 2014 +0100
Committer: Andrew Price <anprice(a)redhat.com>
CommitterDate: Wed Apr 1 16:51:34 2015 +0100
libgfs2: Fix check for O_RDONLY
Spotted by coverity: Execution cannot reach this statement "i->readonly
= 1U;"
This is due to a broken bitwise check for O_RDONLY which is 0 on Linux.
Use O_ACCMODE to mask out the access mode and check it properly.
Signed-off-by: Andrew Price <anprice(a)redhat.com>
---
gfs2/libgfs2/device_geometry.c | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/gfs2/libgfs2/device_geometry.c b/gfs2/libgfs2/device_geometry.c
index 27e846d..1303f11 100644
--- a/gfs2/libgfs2/device_geometry.c
+++ b/gfs2/libgfs2/device_geometry.c
@@ -53,7 +53,7 @@ int lgfs2_get_dev_info(int fd, struct lgfs2_dev_info *i)
case S_IFREG:
i->size = i->stat.st_size;
ret = fcntl(fd, F_GETFL, 0);
- if (ret & O_RDONLY)
+ if ((ret & O_ACCMODE) == O_RDONLY)
i->readonly = 1;
i->io_optimal_size = i->stat.st_blksize;
goto size_check;
9 years
gfs2-utils: RHEL7 - libgfs2: Fail fd comparison if the fds are negative
by Andrew Price
Gitweb: http://git.fedorahosted.org/git/?p=gfs2-utils.git;a=commitdiff;h=7e3a8b6d...
Commit: 7e3a8b6da97574d086aaecb94a08596925b82d41
Parent: 7e83ff820e5d9068ac35e04d09d303fc2465afcb
Author: Andrew Price <anprice(a)redhat.com>
AuthorDate: Fri Oct 3 16:51:26 2014 +0100
Committer: Andrew Price <anprice(a)redhat.com>
CommitterDate: Wed Apr 1 16:51:34 2015 +0100
libgfs2: Fail fd comparison if the fds are negative
Spotted by coverity: "*devfd" is passed to a parameter that cannot be
negative.
This refers to the fstat calls in fdcmp. Guard them with a check for
negative fds.
Signed-off-by: Andrew Price <anprice(a)redhat.com>
---
gfs2/libgfs2/misc.c | 3 +++
1 files changed, 3 insertions(+), 0 deletions(-)
diff --git a/gfs2/libgfs2/misc.c b/gfs2/libgfs2/misc.c
index 9eca24c..a66ca4f 100644
--- a/gfs2/libgfs2/misc.c
+++ b/gfs2/libgfs2/misc.c
@@ -105,6 +105,9 @@ int compute_constants(struct gfs2_sbd *sdp)
static int fdcmp(int fd1, int fd2)
{
struct stat st1, st2;
+
+ if (fd1 < 0 || fd2 < 0)
+ return -1;
if ((fstat(fd1, &st1) != 0) || (fstat(fd2, &st2) != 0))
return -1;
if (S_ISBLK(st1.st_mode) && S_ISBLK(st2.st_mode)) {
9 years
gfs2-utils: RHEL7 - libgfs2: Remove superfluous NULL check from gfs2_rgrp_free
by Andrew Price
Gitweb: http://git.fedorahosted.org/git/?p=gfs2-utils.git;a=commitdiff;h=7e83ff82...
Commit: 7e83ff820e5d9068ac35e04d09d303fc2465afcb
Parent: 90adcabd1d9596e66465f171f2e9f91ad549ed0f
Author: Andrew Price <anprice(a)redhat.com>
AuthorDate: Fri Sep 19 21:24:48 2014 +0100
Committer: Andrew Price <anprice(a)redhat.com>
CommitterDate: Wed Apr 1 16:51:34 2015 +0100
libgfs2: Remove superfluous NULL check from gfs2_rgrp_free
Coverity was complaining that this NULL check indicated that previous
dereferences were bad. Remove the NULL check and let free(3) deal with
NULL conditions (of which there are none in this case).
Signed-off-by: Andrew Price <anprice(a)redhat.com>
---
gfs2/libgfs2/rgrp.c | 3 +--
1 files changed, 1 insertions(+), 2 deletions(-)
diff --git a/gfs2/libgfs2/rgrp.c b/gfs2/libgfs2/rgrp.c
index 1abcc82..ed8e01d 100644
--- a/gfs2/libgfs2/rgrp.c
+++ b/gfs2/libgfs2/rgrp.c
@@ -254,8 +254,7 @@ void gfs2_rgrp_free(struct osi_root *rgrp_tree)
}
gfs2_rgrp_relse(rgd); /* free them all. */
}
- if(rgd->bits)
- free(rgd->bits);
+ free(rgd->bits);
osi_erase(&rgd->node, rgrp_tree);
free(rgd);
}
9 years
gfs2-utils: RHEL7 - libgfs2: Clean up broken rgrp length check
by Andrew Price
Gitweb: http://git.fedorahosted.org/git/?p=gfs2-utils.git;a=commitdiff;h=90adcabd...
Commit: 90adcabd1d9596e66465f171f2e9f91ad549ed0f
Parent: ecba5621c51834b739caee2f7e3692e86e099e83
Author: Andrew Price <anprice(a)redhat.com>
AuthorDate: Fri Sep 19 11:20:05 2014 +0100
Committer: Andrew Price <anprice(a)redhat.com>
CommitterDate: Wed Apr 1 16:51:34 2015 +0100
libgfs2: Clean up broken rgrp length check
This length check had broken logic (!length && length > ...) and always
used the theoretical maximum rgrp size instead of a real maximum for the
fs. Replace the check with a check for a zero length.
Signed-off-by: Andrew Price <anprice(a)redhat.com>
---
gfs2/libgfs2/rgrp.c | 8 +-------
1 files changed, 1 insertions(+), 7 deletions(-)
diff --git a/gfs2/libgfs2/rgrp.c b/gfs2/libgfs2/rgrp.c
index 0d0f000..1abcc82 100644
--- a/gfs2/libgfs2/rgrp.c
+++ b/gfs2/libgfs2/rgrp.c
@@ -154,15 +154,9 @@ void lgfs2_rgrp_bitbuf_free(lgfs2_rgrp_t rg)
uint64_t gfs2_rgrp_read(struct gfs2_sbd *sdp, struct rgrp_tree *rgd)
{
unsigned x, length = rgd->ri.ri_length;
- uint64_t max_rgrp_bitbytes, max_rgrp_len;
struct gfs2_buffer_head **bhs;
- /* Max size of an rgrp is 2GB. Figure out how many blocks that is: */
- max_rgrp_bitbytes = ((2147483648 / sdp->bsize) / GFS2_NBBY);
- max_rgrp_len = max_rgrp_bitbytes / sdp->bsize;
- if (!length && length > max_rgrp_len)
- return -1;
- if (gfs2_check_range(sdp, rgd->ri.ri_addr))
+ if (length == 0 || gfs2_check_range(sdp, rgd->ri.ri_addr))
return -1;
bhs = calloc(length, sizeof(struct gfs2_buffer_head *));
9 years
gfs2-utils: RHEL7 - gfs2_edit: Fix use-after-free in find_wrap_pt
by Andrew Price
Gitweb: http://git.fedorahosted.org/git/?p=gfs2-utils.git;a=commitdiff;h=ecba5621...
Commit: ecba5621c51834b739caee2f7e3692e86e099e83
Parent: fee2852960b318e79ee41849b180bfd7f297d446
Author: Andrew Price <anprice(a)redhat.com>
AuthorDate: Thu Sep 18 17:43:47 2014 +0100
Committer: Andrew Price <anprice(a)redhat.com>
CommitterDate: Wed Apr 1 16:51:34 2015 +0100
gfs2_edit: Fix use-after-free in find_wrap_pt
Spotted by coverity: Calling "brelse(struct gfs2_buffer_head *)"
dereferences freed pointer.
Refactor the find_wrap_pt function to make it easier to manage memory
and minimise scope.
Signed-off-by: Andrew Price <anprice(a)redhat.com>
---
gfs2/edit/journal.c | 70 ++++++++++++++++++++++++++++----------------------
1 files changed, 39 insertions(+), 31 deletions(-)
diff --git a/gfs2/edit/journal.c b/gfs2/edit/journal.c
index 58f4798..81d7a90 100644
--- a/gfs2/edit/journal.c
+++ b/gfs2/edit/journal.c
@@ -297,50 +297,58 @@ static int print_ld_blks(const uint64_t *b, const char *end, int start_line,
return bcount;
}
+static int is_wrap_pt(char *buf, uint64_t *highest_seq)
+{
+ struct gfs2_buffer_head tbh = { .b_data = buf };
+
+ if (get_block_type(&tbh, NULL) == GFS2_METATYPE_LH) {
+ uint64_t seq;
+
+ if (sbd.gfs1) {
+ struct gfs_log_header lh;
+ gfs_log_header_in(&lh, &tbh);
+ seq = lh.lh_sequence;
+ } else {
+ struct gfs2_log_header lh;
+ gfs2_log_header_in(&lh, &tbh);
+ seq = lh.lh_sequence;
+ }
+ if (seq < *highest_seq)
+ return 1;
+ *highest_seq = seq;
+ }
+ return 0;
+}
+
/**
* find_wrap_pt - figure out where a journal wraps
* Returns: The wrap point, in bytes
*/
-static uint64_t find_wrap_pt(struct gfs2_inode *j_inode, char *jbuf,
- uint64_t jblock, uint64_t j_size)
+static uint64_t find_wrap_pt(struct gfs2_inode *ji, char *jbuf, uint64_t jblock, uint64_t j_size)
{
- struct gfs2_buffer_head *j_bh = NULL, dummy_bh;
- uint64_t jb, abs_block;
- int error;
+ uint64_t jb = 0;
uint64_t highest_seq = 0;
for (jb = 0; jb < j_size; jb += (sbd.gfs1 ? 1 : sbd.bsize)) {
+ int found = 0;
+
if (sbd.gfs1) {
- if (j_bh)
- brelse(j_bh);
+ struct gfs2_buffer_head *j_bh;
+
j_bh = bread(&sbd, jblock + jb);
- abs_block = jblock + jb;
- dummy_bh.b_data = j_bh->b_data;
+ found = is_wrap_pt(j_bh->b_data, &highest_seq);
+ brelse(j_bh);
} else {
- error = fsck_readi(j_inode, (void *)jbuf, jb,
- sbd.bsize, &abs_block);
- if (!error) /* end of file */
- break;
- dummy_bh.b_data = jbuf;
- }
- if (get_block_type(&dummy_bh, NULL) == GFS2_METATYPE_LH) {
- struct gfs2_log_header lh;
- struct gfs_log_header lh1;
+ int copied;
+ uint64_t abs_block;
- if (sbd.gfs1) {
- gfs_log_header_in(&lh1, &dummy_bh);
- if (lh1.lh_sequence < highest_seq)
- return jb;
- highest_seq = lh1.lh_sequence;
- } else {
- gfs2_log_header_in(&lh, &dummy_bh);
- if (lh.lh_sequence < highest_seq)
- return jb;
- highest_seq = lh.lh_sequence;
- }
+ copied = fsck_readi(ji, jbuf, jb, sbd.bsize, &abs_block);
+ if (!copied) /* end of file */
+ break;
+ found = is_wrap_pt(jbuf, &highest_seq);
}
- if (j_bh)
- brelse(j_bh);
+ if (found)
+ return jb;
}
return 0;
}
9 years
gfs2-utils: RHEL7 - gfs2_edit: Set umask before calling mkstemp in savemetaopen()
by Andrew Price
Gitweb: http://git.fedorahosted.org/git/?p=gfs2-utils.git;a=commitdiff;h=fee28529...
Commit: fee2852960b318e79ee41849b180bfd7f297d446
Parent: e8fdcc705d2ac36b5151072fc2acef15d0b32ad2
Author: Andrew Price <anprice(a)redhat.com>
AuthorDate: Thu Sep 18 14:51:41 2014 +0100
Committer: Andrew Price <anprice(a)redhat.com>
CommitterDate: Wed Apr 1 16:51:34 2015 +0100
gfs2_edit: Set umask before calling mkstemp in savemetaopen()
Spotted by coverity: Calling "mkstemp(char *)" without securely setting
umask first.
Signed-off-by: Andrew Price <anprice(a)redhat.com>
---
gfs2/edit/savemeta.c | 2 ++
1 files changed, 2 insertions(+), 0 deletions(-)
diff --git a/gfs2/edit/savemeta.c b/gfs2/edit/savemeta.c
index 360b144..5147ee5 100644
--- a/gfs2/edit/savemeta.c
+++ b/gfs2/edit/savemeta.c
@@ -259,6 +259,7 @@ static struct metafd savemetaopen(char *out_fn, int gziplevel)
struct metafd mfd = {-1, NULL, NULL, gziplevel};
char gzmode[3] = "w9";
char dft_fn[] = DFT_SAVE_FILE;
+ mode_t mask = umask(S_IXUSR | S_IRWXG | S_IRWXO);
if (!out_fn) {
out_fn = dft_fn;
@@ -266,6 +267,7 @@ static struct metafd savemetaopen(char *out_fn, int gziplevel)
} else {
mfd.fd = open(out_fn, O_RDWR | O_CREAT, 0644);
}
+ umask(mask);
mfd.filename = out_fn;
if (mfd.fd < 0) {
9 years
gfs2-utils: RHEL7 - gfs2_edit: Fix signed value used as array index in print_ld_blks
by Andrew Price
Gitweb: http://git.fedorahosted.org/git/?p=gfs2-utils.git;a=commitdiff;h=e8fdcc70...
Commit: e8fdcc705d2ac36b5151072fc2acef15d0b32ad2
Parent: 0e67e7af3b13e47aff2957ccc00c077a68b3f025
Author: Andrew Price <anprice(a)redhat.com>
AuthorDate: Thu Sep 18 14:27:17 2014 +0100
Committer: Andrew Price <anprice(a)redhat.com>
CommitterDate: Wed Apr 1 16:51:34 2015 +0100
gfs2_edit: Fix signed value used as array index in print_ld_blks
Spotted by coverity: Using variable "type" as an index to array
"allocdesc[sbd.gfs1]".
Signed-off-by: Andrew Price <anprice(a)redhat.com>
---
gfs2/edit/journal.c | 7 +++++--
1 files changed, 5 insertions(+), 2 deletions(-)
diff --git a/gfs2/edit/journal.c b/gfs2/edit/journal.c
index 5b824a4..58f4798 100644
--- a/gfs2/edit/journal.c
+++ b/gfs2/edit/journal.c
@@ -263,9 +263,12 @@ static int print_ld_blks(const uint64_t *b, const char *end, int start_line,
j_bmap_bh = bread(&sbd, abs_block +
bcount);
rgd->bits[bmap].bi_bh = j_bmap_bh;
- type = lgfs2_get_bitmap(&sbd, tblk,
- rgd);
+ type = lgfs2_get_bitmap(&sbd, tblk, rgd);
brelse(j_bmap_bh);
+ if (type < 0) {
+ perror("Error printing log descriptor blocks");
+ exit(1);
+ }
rgd->bits[bmap].bi_bh = save_bh;
print_gfs2("bit for blk 0x%llx is %d "
"(%s)",
9 years
gfs2-utils: RHEL7 - gfs2_convert: Fix potential memory leaks in adjust_inode
by Andrew Price
Gitweb: http://git.fedorahosted.org/git/?p=gfs2-utils.git;a=commitdiff;h=0e67e7af...
Commit: 0e67e7af3b13e47aff2957ccc00c077a68b3f025
Parent: e2ee1e897df004e2843be27f10af3a30ecb59d5d
Author: Andrew Price <anprice(a)redhat.com>
AuthorDate: Thu Sep 18 14:07:32 2014 +0100
Committer: Andrew Price <anprice(a)redhat.com>
CommitterDate: Wed Apr 1 16:51:34 2015 +0100
gfs2_convert: Fix potential memory leaks in adjust_inode
Spotted by coverity: Variable "inode" going out of scope leaks the
storage it points to.
Signed-off-by: Andrew Price <anprice(a)redhat.com>
---
gfs2/convert/gfs2_convert.c | 11 +++++++----
1 files changed, 7 insertions(+), 4 deletions(-)
diff --git a/gfs2/convert/gfs2_convert.c b/gfs2/convert/gfs2_convert.c
index 1e83222..8b86663 100644
--- a/gfs2/convert/gfs2_convert.c
+++ b/gfs2/convert/gfs2_convert.c
@@ -885,7 +885,7 @@ static int adjust_inode(struct gfs2_sbd *sbp, struct gfs2_buffer_head *bh)
if (!fixdir) {
/*FIXME: Same message as fix_cdpn_symlink */
log_crit(_("Error: out of memory.\n"));
- return -1;
+ goto err_freei;
}
memset(fixdir, 0, sizeof(struct inode_block));
fixdir->di_addr = inode->i_di.di_num.no_addr;
@@ -939,18 +939,18 @@ static int adjust_inode(struct gfs2_sbd *sbp, struct gfs2_buffer_head *bh)
inode->i_di.di_generation = 0;
if (adjust_indirect_blocks(sbp, inode))
- return -1;
+ goto err_freei;
/* Check for cdpns */
if (S_ISLNK(inode->i_di.di_mode)) {
ret = fix_cdpn_symlink(sbp, bh, inode);
if (ret)
- return -1;
+ goto err_freei;
}
/* Check for extended attributes */
if (inode->i_di.di_eattr) {
ret = fix_xattr(sbp, bh, inode);
if (ret)
- return -1;
+ goto err_freei;
}
}
@@ -958,6 +958,9 @@ static int adjust_inode(struct gfs2_sbd *sbp, struct gfs2_buffer_head *bh)
inode_put(&inode); /* does gfs2_dinode_out if modified */
sbp->md.next_inum++; /* update inode count */
return 0;
+err_freei:
+ inode_put(&inode);
+ return -1;
} /* adjust_inode */
static int next_rg_meta(struct rgrp_tree *rgd, uint64_t *block, int first)
9 years