Skip to contentSkip to conversation

export: fix string handling of namespace in EXPORT_SYMBOL_NS

PATCH Superseded Greg Kroah-Hartman 3 participants 4 messages Jan 8, 2022 – Apr 27, 2022

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 export: fix string handling of namespace in EXPORT_SYMBOL_NS

Commit c3a6cf19e695 ("export: avoid code duplication in include/linux/export.h") broke the ability for a defined string to be used as a namespace value. Fix this up by adding another layer of indirection to preserve the previous functionality.

Fixes c3a6cf19e695 ("export: avoid code duplication in include/linux/export.h")
Cc Miroslav Benes <[email protected]>
Cc Emil Velikov <[email protected]>
Cc Jessica Yu <[email protected]>
Cc Quentin Perret <[email protected]>
Cc Masahiro Yamada <[email protected]>
Cc Matthias Maennich <[email protected]>

---
Note, I found this while forward porting an out-of-tree Android kernel patch from 5.4 to 5.10 that used module namespaces to help wall-off vfs symbols from being used by non-filesystem modules. This issue does not affect any in-kernel code, so I am not so sure if it really is needed here, but it does restore the previous functionality that was being used in older kernels so it might be good to put back in case others want to do much the same thing.

 include/linux/export.h | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
include/linux/export.h +4 -2
index 27d848712b90..9a992809f57d 100644
@@ -162,8 +162,10 @@ struct kernel_symbol {
 
 #define EXPORT_SYMBOL(sym)		_EXPORT_SYMBOL(sym, "")
 #define EXPORT_SYMBOL_GPL(sym)		_EXPORT_SYMBOL(sym, "_gpl")
-#define EXPORT_SYMBOL_NS(sym, ns)	__EXPORT_SYMBOL(sym, "", #ns)
-#define EXPORT_SYMBOL_NS_GPL(sym, ns)	__EXPORT_SYMBOL(sym, "_gpl", #ns)
+#define _EXPORT_SYMBOL_NS(sym, ns)	__EXPORT_SYMBOL(sym, "", #ns)
+#define _EXPORT_SYMBOL_NS_GPL(sym, ns)	__EXPORT_SYMBOL(sym, "_gpl", #ns)
+#define EXPORT_SYMBOL_NS(sym, ns)	_EXPORT_SYMBOL_NS(sym, ns)
+#define EXPORT_SYMBOL_NS_GPL(sym, ns)	_EXPORT_SYMBOL_NS_GPL(sym, ns)
 
 #endif /* !__ASSEMBLY__ */
 
Signature · 1 line
2.34.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 5 lines · Greg Kroah-Hartman

Commit c3a6cf19e695 ("export: avoid code duplication in include/linux/export.h") broke the ability for a defined string to be used as a namespace value. Fix this up by adding another layer of indirection to preserve the previous functionality.

Quoted 8 lines
Fixes c3a6cf19e695 ("export: avoid code duplication in include/linux/export.h")
Cc Miroslav Benes <[email protected]>
Cc Emil Velikov <[email protected]>
Cc Jessica Yu <[email protected]>
Cc Quentin Perret <[email protected]>
Cc Masahiro Yamada <[email protected]>
Cc Matthias Maennich <[email protected]>

Cheers,
Matthias

Quoted 32 lines

---
Note, I found this while forward porting an out-of-tree Android kernel patch from 5.4 to 5.10 that used module namespaces to help wall-off vfs symbols from being used by non-filesystem modules. This issue does not affect any in-kernel code, so I am not so sure if it really is needed here, but it does restore the previous functionality that was being used in older kernels so it might be good to put back in case others want to do much the same thing.

include/linux/export.h | 6 ++++--

1 file changed, 4 insertions(+), 2 deletions(-)
include/linux/export.h +4 -2
index 27d848712b90..9a992809f57d 100644
@@ -162,8 +162,10 @@ struct kernel_symbol {
 
 #define EXPORT_SYMBOL(sym)		_EXPORT_SYMBOL(sym, "")
 #define EXPORT_SYMBOL_GPL(sym)		_EXPORT_SYMBOL(sym, "_gpl")
-#define EXPORT_SYMBOL_NS(sym, ns)	__EXPORT_SYMBOL(sym, "", #ns)
-#define EXPORT_SYMBOL_NS_GPL(sym, ns)	__EXPORT_SYMBOL(sym, "_gpl", #ns)
+#define _EXPORT_SYMBOL_NS(sym, ns)	__EXPORT_SYMBOL(sym, "", #ns)
+#define _EXPORT_SYMBOL_NS_GPL(sym, ns)	__EXPORT_SYMBOL(sym, "_gpl", #ns)
+#define EXPORT_SYMBOL_NS(sym, ns)	_EXPORT_SYMBOL_NS(sym, ns)
+#define EXPORT_SYMBOL_NS_GPL(sym, ns)	_EXPORT_SYMBOL_NS_GPL(sym, ns)
 
 #endif /* !__ASSEMBLY__ */
 
Signature · 1 line
2.34.1
#2 lore raw
In reply to Greg Kroah-Hartman
Quoted 44 lines · Greg Kroah-Hartman

Commit c3a6cf19e695 ("export: avoid code duplication in include/linux/export.h") broke the ability for a defined string to be used as a namespace value. Fix this up by adding another layer of indirection to preserve the previous functionality.

Fixes c3a6cf19e695 ("export: avoid code duplication in include/linux/export.h")
Cc Miroslav Benes <[email protected]>
Cc Emil Velikov <[email protected]>
Cc Jessica Yu <[email protected]>
Cc Quentin Perret <[email protected]>
Cc Masahiro Yamada <[email protected]>
Cc Matthias Maennich <[email protected]>

---
Note, I found this while forward porting an out-of-tree Android kernel patch from 5.4 to 5.10 that used module namespaces to help wall-off vfs symbols from being used by non-filesystem modules. This issue does not affect any in-kernel code, so I am not so sure if it really is needed here, but it does restore the previous functionality that was being used in older kernels so it might be good to put back in case others want to do much the same thing.

 include/linux/export.h | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
include/linux/export.h +4 -3
index 27d848712b90..9a992809f57d 100644
@@ -162,8 +162,10 @@ struct kernel_symbol {
 
 #define EXPORT_SYMBOL(sym)             _EXPORT_SYMBOL(sym, "")
 #define EXPORT_SYMBOL_GPL(sym)         _EXPORT_SYMBOL(sym, "_gpl")
-#define EXPORT_SYMBOL_NS(sym, ns)      __EXPORT_SYMBOL(sym, "", #ns)
-#define EXPORT_SYMBOL_NS_GPL(sym, ns)  __EXPORT_SYMBOL(sym, "_gpl", #ns)
+#define _EXPORT_SYMBOL_NS(sym, ns)     __EXPORT_SYMBOL(sym, "", #ns)
+#define _EXPORT_SYMBOL_NS_GPL(sym, ns) __EXPORT_SYMBOL(sym, "_gpl", #ns)
+#define EXPORT_SYMBOL_NS(sym, ns)      _EXPORT_SYMBOL_NS(sym, ns)
+#define EXPORT_SYMBOL_NS_GPL(sym, ns)  _EXPORT_SYMBOL_NS_GPL(sym, ns)
 
 #endif /* !__ASSEMBLY__ */
 
--
Quoted 2 lines

2.34.1

I see __stringify() a few files above.
So, you can use it here as well.

Does the following code work? (untested)

include/linux/export.h +2 -1
index 27d848712b90..5910ccb66ca2 100644
@@ -2,6 +2,8 @@
 #ifndef _LINUX_EXPORT_H
 #define _LINUX_EXPORT_H
 
+#include <linux/stringify.h>
+
 /*
  * Export symbols from the kernel to modules.  Forked from module.h
  * to reduce the amount of pointless cruft we feed to gcc when only
@@ -154,7 +156,6 @@ struct kernel_symbol {
 #endif /* CONFIG_MODULES */
 
 #ifdef DEFAULT_SYMBOL_NAMESPACE
-#include <linux/stringify.h>
 #define _EXPORT_SYMBOL(sym, sec)       __EXPORT_SYMBOL(sym, sec,

__stringify(DEFAULT_SYMBOL_NAMESPACE))
#else
#define _EXPORT_SYMBOL(sym, sec) __EXPORT_SYMBOL(sym, sec, "")
@@ -162,8 +163,8 @@ struct kernel_symbol {

 #define EXPORT_SYMBOL(sym)             _EXPORT_SYMBOL(sym, "")
 #define EXPORT_SYMBOL_GPL(sym)         _EXPORT_SYMBOL(sym, "_gpl")
-#define EXPORT_SYMBOL_NS(sym, ns)      __EXPORT_SYMBOL(sym, "", #ns)
-#define EXPORT_SYMBOL_NS_GPL(sym, ns)  __EXPORT_SYMBOL(sym, "_gpl", #ns)
+#define EXPORT_SYMBOL_NS(sym, ns)      __EXPORT_SYMBOL(sym, "",

__stringify(ns))
+#define EXPORT_SYMBOL_NS_GPL(sym, ns) __EXPORT_SYMBOL(sym, "_gpl", __stringify(ns))

#endif /* !__ASSEMBLY__ */

Signature · 2 lines
Best Regards
Masahiro Yamada
#3 lore raw
Quoted 92 lines · Masahiro Yamada
Quoted 44 lines · Greg Kroah-Hartman

Commit c3a6cf19e695 ("export: avoid code duplication in include/linux/export.h") broke the ability for a defined string to be used as a namespace value. Fix this up by adding another layer of indirection to preserve the previous functionality.

Fixes c3a6cf19e695 ("export: avoid code duplication in include/linux/export.h")
Cc Miroslav Benes <[email protected]>
Cc Emil Velikov <[email protected]>
Cc Jessica Yu <[email protected]>
Cc Quentin Perret <[email protected]>
Cc Masahiro Yamada <[email protected]>
Cc Matthias Maennich <[email protected]>

---
Note, I found this while forward porting an out-of-tree Android kernel patch from 5.4 to 5.10 that used module namespaces to help wall-off vfs symbols from being used by non-filesystem modules. This issue does not affect any in-kernel code, so I am not so sure if it really is needed here, but it does restore the previous functionality that was being used in older kernels so it might be good to put back in case others want to do much the same thing.

 include/linux/export.h | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
include/linux/export.h +4 -3
index 27d848712b90..9a992809f57d 100644
@@ -162,8 +162,10 @@ struct kernel_symbol {
 
 #define EXPORT_SYMBOL(sym)             _EXPORT_SYMBOL(sym, "")
 #define EXPORT_SYMBOL_GPL(sym)         _EXPORT_SYMBOL(sym, "_gpl")
-#define EXPORT_SYMBOL_NS(sym, ns)      __EXPORT_SYMBOL(sym, "", #ns)
-#define EXPORT_SYMBOL_NS_GPL(sym, ns)  __EXPORT_SYMBOL(sym, "_gpl", #ns)
+#define _EXPORT_SYMBOL_NS(sym, ns)     __EXPORT_SYMBOL(sym, "", #ns)
+#define _EXPORT_SYMBOL_NS_GPL(sym, ns) __EXPORT_SYMBOL(sym, "_gpl", #ns)
+#define EXPORT_SYMBOL_NS(sym, ns)      _EXPORT_SYMBOL_NS(sym, ns)
+#define EXPORT_SYMBOL_NS_GPL(sym, ns)  _EXPORT_SYMBOL_NS_GPL(sym, ns)
 
 #endif /* !__ASSEMBLY__ */
 
--
Quoted 2 lines

2.34.1

I see __stringify() a few files above.
So, you can use it here as well.

Does the following code work? (untested)

include/linux/export.h +2 -1
index 27d848712b90..5910ccb66ca2 100644
@@ -2,6 +2,8 @@
 #ifndef _LINUX_EXPORT_H
 #define _LINUX_EXPORT_H
 
+#include <linux/stringify.h>
+
 /*
  * Export symbols from the kernel to modules.  Forked from module.h
  * to reduce the amount of pointless cruft we feed to gcc when only
@@ -154,7 +156,6 @@ struct kernel_symbol {
 #endif /* CONFIG_MODULES */
 
 #ifdef DEFAULT_SYMBOL_NAMESPACE
-#include <linux/stringify.h>
 #define _EXPORT_SYMBOL(sym, sec)       __EXPORT_SYMBOL(sym, sec,
 __stringify(DEFAULT_SYMBOL_NAMESPACE))
 #else

#define _EXPORT_SYMBOL(sym, sec) __EXPORT_SYMBOL(sym, sec, "")

include/linux/export.h +2 -2
@@ -162,8 +163,8 @@ struct kernel_symbol {
 
 #define EXPORT_SYMBOL(sym)             _EXPORT_SYMBOL(sym, "")
 #define EXPORT_SYMBOL_GPL(sym)         _EXPORT_SYMBOL(sym, "_gpl")
-#define EXPORT_SYMBOL_NS(sym, ns)      __EXPORT_SYMBOL(sym, "", #ns)
-#define EXPORT_SYMBOL_NS_GPL(sym, ns)  __EXPORT_SYMBOL(sym, "_gpl", #ns)
+#define EXPORT_SYMBOL_NS(sym, ns)      __EXPORT_SYMBOL(sym, "",
 __stringify(ns))
+#define EXPORT_SYMBOL_NS_GPL(sym, ns)  __EXPORT_SYMBOL(sym, "_gpl",
 __stringify(ns))
 
Quoted 1 line

#endif /* !__ASSEMBLY__ */

Sorry for the long delay, but yes, this does seem to resolve the issue for me. I'll respin this and resend, thanks!

greg k-h