aboutsummaryrefslogtreecommitdiffstats
path: root/patches/misc/modpost-srcversion-sometimes-incorrect.patch
blob: ab8d1b7cac1a8d72e90f1e41b7f8c13df57da041 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
From 74f6cd2b6976e37491779fcb1bc4966d3a61492c Mon Sep 17 00:00:00 2001
From: Juro Bystricky <juro.bystricky@intel.com>
Date: Fri, 30 Mar 2018 10:14:05 -0700
Subject: [PATCH] modpost: srcversion sometimes incorrect

"srcversion" field inserted into module modinfo section contains a
sum of the source files which made it. However, this field can
be incorrect. Building the same module can end up having inconsistent
srcversion field eventhough the sources remain the same.
This can be reproduced by building modules in a deeply nested directory,
but other factors contribute as well.

The reason for incorrect srcversion is that some source files can be
simply silently skipped from the checksum calculation due to limited
buffer space for line parsing.

This patch addresses two issues:

1. Allocates a larger line buffer (32k vs 4k).
2. Issues a warning if a line length exceeds the line buffer.

Signed-off-by: Juro Bystricky <juro.bystricky@intel.com>
Signed-off-by: Bruce Ashfield <bruce.ashfield@windriver.com>
---
 scripts/mod/modpost.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c
index b9bd26f3e6c9..7d2f1d659a43 100644
--- a/scripts/mod/modpost.c
+++ b/scripts/mod/modpost.c
@@ -385,9 +385,10 @@ void *grab_file(const char *filename, unsigned long *size)
   * spaces in the beginning of the line is trimmed away.
   * Return a pointer to a static buffer.
   **/
+#define MODPOST_MAX_LINE 32768
 char *get_next_line(unsigned long *pos, void *file, unsigned long size)
 {
-	static char line[4096];
+	static char line[MODPOST_MAX_LINE];
 	int skip = 1;
 	size_t len = 0;
 	signed char *p = (signed char *)file + *pos;
@@ -402,8 +403,11 @@ char *get_next_line(unsigned long *pos, void *file, unsigned long size)
 		if (*p != '\n' && (*pos < size)) {
 			len++;
 			*s++ = *p++;
-			if (len > 4095)
+			if (len > (sizeof(line)-1)) {
+				warn(" %s: line exceeds buffer size %zu bytes\n"
+				     , __func__, sizeof(line));
 				break; /* Too long, stop */
+			}
 		} else {
 			/* End of string */
 			*s = '\0';
-- 
2.5.0