Skip to contentSkip to conversation

glocktop: dlmwaiters above 100 fixes

PATCH New Alexander Aring 2 participants 4 messages Mar 11, 2021 – Mar 13, 2021

lore
Share & tools
lore
#0 lore raw

cover glocktop: dlmwaiters above 100 fixes

Hi,

these patches fixes issues for me with glocktop. I got a:

*** buffer overflow detected ***: terminated
Aborted (core dumped)

debugging with gdb figured out that there are some maximum limitation to handle dlm waiters which was in my case 117. This patches increased the maximum allowed dlm waiters. These limitations are still static and should be changed to dynamic allocation in due courses otherwise buffer overflow happens again.

- Alex

Alexander Aring (2):
glocktop: use MAX_LINES for dlmwlines
glocktop: allocate fsdlm dynamically

 gfs2/glocktop/glocktop.c | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)
Signature · 1 line
2.26.2
#1 lore raw

PATCH 1/2 glocktop: use MAX_LINES for dlmwlines

This patch uses MAX_LINES to handle 100 DLM waiters and above. There is still a limitation but very unlikely to hit.

---
 gfs2/glocktop/glocktop.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
gfs2/glocktop/glocktop.c +1 -1
index bd7fcf02..9df87d18 100644
@@ -159,7 +159,7 @@ struct mount_point {
 	struct gfs2_sb sb;
 };
 struct mount_point *mounts;
-char dlmwlines[100][96]; /* waiters lines */
+char dlmwlines[MAX_LINES][96]; /* waiters lines */
 char dlmglines[MAX_LINES][97]; /* granted lines */
 char contended_filenames[MAX_FILES][PATH_MAX];
 unsigned long long contended_blocks[MAX_FILES];
Signature · 1 line
2.26.2
#2 lore raw

PATCH 2/2 glocktop: allocate fsdlm dynamically

In reply to Alexander Aring

This patch allocates the fsdlm string dynamically with respect of dlmwaiters. The fsdlm has at least the dlmwaiters length, the 105 bytes are for some other predicted max length strings.

---
 gfs2/glocktop/glocktop.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)
gfs2/glocktop/glocktop.c +8 -2
index 9df87d18..0096a2a5 100644
@@ -1605,7 +1605,7 @@ static void parse_glocks_file(int fd, const char *fsname, int dlmwaiters,
 			      int dlmgrants, int trace_dir_path,
 			      int show_held, int help, int summary)
 {
-	char fstitle[96], fsdlm[105];
+	char fstitle[96], *fsdlm;
 	char ctimestr[64];
 	time_t t;
 	int i;
@@ -1615,7 +1615,12 @@ static void parse_glocks_file(int fd, const char *fsname, int dlmwaiters,
 	strftime(ctimestr, 64, "%a %b %d %T %Y", localtime(&t));
 	ctimestr[63] = '\0';
 	memset(fstitle, 0, sizeof(fstitle));
-	memset(fsdlm, 0, sizeof(fsdlm));
+	fsdlm = calloc(1, 105 + dlmwaiters);
+	if (!fsdlm) {
+		printf("Failed to allocate fsdlm\n");
+		exit(-1);
+	}
+
 	sprintf(fstitle, "@ %.22s       %s ", fsname, ctimestr);
 	if (dlmwaiters) {
 		sprintf(fsdlm, "dlm: %s/%s/%s [", dlm_dirtbl_size,
@@ -1628,6 +1633,7 @@ static void parse_glocks_file(int fd, const char *fsname, int dlmwaiters,
 	}
 	attron(A_BOLD);
 	print_it(NULL, "%s @%s %s", NULL, fstitle, hostname, fsdlm);
+	free(fsdlm);
 	eol(0);
 	attroff(A_BOLD);
 	glock_details(fd, fsname, dlmwaiters, dlmgrants, trace_dir_path,
Signature · 1 line
2.26.2
Applied
#3 lore raw

cover glocktop: dlmwaiters above 100 fixes

In reply to Alexander Aring
Quoted 14 lines · Alexander Aring

Hi,

these patches fixes issues for me with glocktop. I got a:

*** buffer overflow detected ***: terminated
Aborted (core dumped)

debugging with gdb figured out that there are some maximum limitation to handle dlm waiters which was in my case 117. This patches increased the maximum allowed dlm waiters. These limitations are still static and should be changed to dynamic allocation in due courses otherwise buffer overflow happens again.

Quoted 9 lines

- Alex

Alexander Aring (2):
glocktop: use MAX_LINES for dlmwlines
glocktop: allocate fsdlm dynamically

  gfs2/glocktop/glocktop.c | 12 +++++++++---
  1 file changed, 9 insertions(+), 3 deletions(-)

Applied. Thanks Alex.

Andy