Skip to contentSkip to conversation

modinfo: don't parse built-in for explicitly given module files

PATCH In review Takashi Iwai 5 participants 9 messages Aug 18, 2021 – Aug 19, 2021

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 modinfo: don't parse built-in for explicitly given module files

A recent bug report showed that modinfo doesn't give the signature information for certain modules, and it turned out to happen only on the modules that are built-in on the running kernel; then modinfo skips the signature check, as if the target module file never exists. The behavior is, however, inconsistent when modinfo is performed for external modules (no matter which kernel version is) and the module file path is explicitly given by a command-line argument, which guarantees the presence of the module file itself.

This patch addresses the regression by checking the presence of the module path at first before checking the built-in module.

Fixes e7e2cb61fa9f ("modinfo: Show information about built-in modules")
---
 libkmod/libkmod-module.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
libkmod/libkmod-module.c +2 -1
index 6e0ff1a99604..9e878a5345a1 100644
@@ -2292,7 +2292,8 @@ KMOD_EXPORT int kmod_module_get_info(const struct kmod_module *mod, struct kmod_
 	assert(*list == NULL);
 
 	/* remove const: this can only change internal state */
-	if (kmod_module_is_builtin((struct kmod_module *)mod)) {
+	if (!kmod_module_get_path(mod) &&
+	    kmod_module_is_builtin((struct kmod_module *)mod)) {
 		count = kmod_builtin_get_modinfo(mod->ctx,
 						kmod_module_get_name(mod),
 						&strings);
Signature · 1 line
2.26.2
Reviewed-by on v1 1/1
#1 lore raw
Quoted 9 lines · Takashi Iwai

A recent bug report showed that modinfo doesn't give the signature information for certain modules, and it turned out to happen only on the modules that are built-in on the running kernel; then modinfo skips the signature check, as if the target module file never exists. The behavior is, however, inconsistent when modinfo is performed for external modules (no matter which kernel version is) and the module file path is explicitly given by a command-line argument, which guarantees the presence of the module file itself.

Quoted 6 lines

This patch addresses the regression by checking the presence of the module path at first before checking the built-in module.

Fixes e7e2cb61fa9f ("modinfo: Show information about built-in modules")

LGTM

Thanks

Quoted 21 lines
---
 libkmod/libkmod-module.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
libkmod/libkmod-module.c +2 -1
index 6e0ff1a99604..9e878a5345a1 100644
@@ -2292,7 +2292,8 @@ KMOD_EXPORT int kmod_module_get_info(const struct kmod_module *mod, struct kmod_
 	assert(*list == NULL);
 
 	/* remove const: this can only change internal state */
-	if (kmod_module_is_builtin((struct kmod_module *)mod)) {
+	if (!kmod_module_get_path(mod) &&
+	    kmod_module_is_builtin((struct kmod_module *)mod)) {
 		count = kmod_builtin_get_modinfo(mod->ctx,
 						kmod_module_get_name(mod),
 						&strings);
Signature · 1 line
2.26.2
#3 lore raw
In reply to Takashi Iwai
Quoted 25 lines · Takashi Iwai

A recent bug report showed that modinfo doesn't give the signature information for certain modules, and it turned out to happen only on the modules that are built-in on the running kernel; then modinfo skips the signature check, as if the target module file never exists. The behavior is, however, inconsistent when modinfo is performed for external modules (no matter which kernel version is) and the module file path is explicitly given by a command-line argument, which guarantees the presence of the module file itself.

This patch addresses the regression by checking the presence of the module path at first before checking the built-in module.

Fixes e7e2cb61fa9f ("modinfo: Show information about built-in modules")
---
 libkmod/libkmod-module.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
libkmod/libkmod-module.c +0 -0
index 6e0ff1a99604..9e878a5345a1 100644

libkmod/libkmod-module.c KMOD_EXPORT int kmod_module_get_info(const struct kmod_module *mod, struct kmod_ · line 2296

Quoted 6 lines
libkmod/libkmod-module.c +2 -1
@@ -2292,7 +2292,8 @@ KMOD_EXPORT int kmod_module_get_info(const struct kmod_module *mod, struct kmod_
        assert(*list == NULL);
 
        /* remove const: this can only change internal state */
-       if (kmod_module_is_builtin((struct kmod_module *)mod)) {
+       if (!kmod_module_get_path(mod) &&
+           kmod_module_is_builtin((struct kmod_module *)mod)) {

thanks for spotting this... but I'm not sure this is the right fix. kmod_module_is_builtin() shouldn't return true if the module was created by path rather than lookup. It seems we should rather set mod->builtin = KMOD_MODULE_BUILTIN_NO in kmod_module_new_from_path(). This would also fix the use of kmod_module_is_builtin() directly by applications.

Since the builtin check uses lazy initialization, the default is KMOD_MODULE_BUILTIN_UNKNOWN, hence the bug here.

Lucas De Marchi

Quoted 6 lines
libkmod/libkmod-module.c +0 -1
                count = kmod_builtin_get_modinfo(mod->ctx,
                                                kmod_module_get_name(mod),
                                                &strings);
--

2.26.2

#4 lore raw

PATCH 1/1 libkmod: Set builtin to no when module is created from path.

Something like this?

Thanks

Michal

--------------------------------------------------------------------

A recent bug report showed that modinfo doesn't give the signature information for certain modules, and it turned out to happen only on the modules that are built-in on the running kernel; then modinfo skips the signature check, as if the target module file never exists. The behavior is, however, inconsistent when modinfo is performed for external modules (no matter which kernel version is) and the module file path is explicitly given by a command-line argument, which guarantees the presence of the module file itself.

---
 libkmod/libkmod-module.c | 18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)
libkmod/libkmod-module.c +9 -9
index 9e878a5345a1..53b220d492e8 100644
@@ -432,18 +432,18 @@ KMOD_EXPORT int kmod_module_new_from_path(struct kmod_ctx *ctx,
 		}
 
 		*mod = kmod_module_ref(m);
-		return 0;
-	}
+	} else {
+		err = kmod_module_new(ctx, name, name, namelen, NULL, 0, &m);
+		if (err < 0) {
+			free(abspath);
+			return err;
+		}
 
-	err = kmod_module_new(ctx, name, name, namelen, NULL, 0, &m);
-	if (err < 0) {
-		free(abspath);
-		return err;
+		m->path = abspath;
+		*mod = m;
 	}
 
-	m->path = abspath;
-	*mod = m;
-
+	(*mod)->builtin = KMOD_MODULE_BUILTIN_NO;
 	return 0;
 }
 
Signature · 1 line
2.31.1
#5 lore raw

Re: [PATCH] libkmod: Set builtin to no when module is created from path.

Quoted 2 lines · Michal Suchanek

Something like this?

yep. Just a matter of style but I think I like the *mod = m as the last thing. Let me send it with that additional change.

thanks
Lucas De Marchi

Quoted 60 lines

Thanks

Michal

--------------------------------------------------------------------

A recent bug report showed that modinfo doesn't give the signature information for certain modules, and it turned out to happen only on the modules that are built-in on the running kernel; then modinfo skips the signature check, as if the target module file never exists. The behavior is, however, inconsistent when modinfo is performed for external modules (no matter which kernel version is) and the module file path is explicitly given by a command-line argument, which guarantees the presence of the module file itself.

---
 libkmod/libkmod-module.c | 18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)
libkmod/libkmod-module.c +9 -10
index 9e878a5345a1..53b220d492e8 100644
@@ -432,18 +432,18 @@ KMOD_EXPORT int kmod_module_new_from_path(struct kmod_ctx *ctx,
                }
 
                *mod = kmod_module_ref(m);
-               return 0;
-       }
+       } else {
+               err = kmod_module_new(ctx, name, name, namelen, NULL, 0, &m);
+               if (err < 0) {
+                       free(abspath);
+                       return err;
+               }
 
-       err = kmod_module_new(ctx, name, name, namelen, NULL, 0, &m);
-       if (err < 0) {
-               free(abspath);
-               return err;
+               m->path = abspath;
+               *mod = m;
        }
 
-       m->path = abspath;
-       *mod = m;
-
+       (*mod)->builtin = KMOD_MODULE_BUILTIN_NO;
        return 0;
 }
 
--

2.31.1

#6 lore raw

PATCH v2 1/1 libkmod: Set builtin to no when module is created from path.

In reply to Michal Suchanek

From: Michal Suchanek <[email protected]>

A recent bug report showed that modinfo doesn't give the signature information for certain modules, and it turned out to happen only on the modules that are built-in on the running kernel; then modinfo skips the signature check, as if the target module file never exists. The behavior is, however, inconsistent when modinfo is performed for external modules (no matter which kernel version is) and the module file path is explicitly given by a command-line argument, which guarantees the presence of the module file itself.

---
 libkmod/libkmod-module.c | 17 +++++++++--------
 1 file changed, 9 insertions(+), 8 deletions(-)
libkmod/libkmod-module.c +9 -8
index 6e0ff1a..6f7747c 100644
@@ -431,17 +431,18 @@ KMOD_EXPORT int kmod_module_new_from_path(struct kmod_ctx *ctx,
 			return -EEXIST;
 		}
 
-		*mod = kmod_module_ref(m);
-		return 0;
-	}
+		kmod_module_ref(m);
+	} else {
+		err = kmod_module_new(ctx, name, name, namelen, NULL, 0, &m);
+		if (err < 0) {
+			free(abspath);
+			return err;
+		}
 
-	err = kmod_module_new(ctx, name, name, namelen, NULL, 0, &m);
-	if (err < 0) {
-		free(abspath);
-		return err;
+		m->path = abspath;
 	}
 
-	m->path = abspath;
+	m->builtin = KMOD_MODULE_BUILTIN_NO;
 	*mod = m;
 
 	return 0;
Signature · 1 line
2.31.1
#7 lore raw

PATCH 1/1 libkmod: Set builtin to no when module is created from path.

From: Michal Suchanek <[email protected]>

A recent bug report showed that modinfo doesn't give the signature information for certain modules, and it turned out to happen only on the modules that are built-in on the running kernel; then modinfo skips the signature check, as if the target module file never exists. The behavior is, however, inconsistent when modinfo is performed for external modules (no matter which kernel version is) and the module file path is explicitly given by a command-line argument, which guarantees the presence of the module file itself.

---
 libkmod/libkmod-module.c | 17 +++++++++--------
 1 file changed, 9 insertions(+), 8 deletions(-)
libkmod/libkmod-module.c +9 -8
index 6e0ff1a..6f7747c 100644
@@ -431,17 +431,18 @@ KMOD_EXPORT int kmod_module_new_from_path(struct kmod_ctx *ctx,
 			return -EEXIST;
 		}
 
-		*mod = kmod_module_ref(m);
-		return 0;
-	}
+		kmod_module_ref(m);
+	} else {
+		err = kmod_module_new(ctx, name, name, namelen, NULL, 0, &m);
+		if (err < 0) {
+			free(abspath);
+			return err;
+		}
 
-	err = kmod_module_new(ctx, name, name, namelen, NULL, 0, &m);
-	if (err < 0) {
-		free(abspath);
-		return err;
+		m->path = abspath;
 	}
 
-	m->path = abspath;
+	m->builtin = KMOD_MODULE_BUILTIN_NO;
 	*mod = m;
 
 	return 0;
Signature · 1 line
2.31.1