Re: [PATCH] export: fix string handling of namespace in EXPORT_SYMBOL_NS

From: Matthias Maennich
Date: Mon Jan 10 2022 - 12:39:00 EST


On Sat, Jan 08, 2022 at 03:04:15PM +0100, Greg Kroah-Hartman wrote:
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 <mbenes@xxxxxxx>
Cc: Emil Velikov <emil.l.velikov@xxxxxxxxx>
Cc: Jessica Yu <jeyu@xxxxxxxxxx>
Cc: Quentin Perret <qperret@xxxxxxxxxx>
Cc: Masahiro Yamada <yamada.masahiro@xxxxxxxxxxxxx>
Cc: Matthias Maennich <maennich@xxxxxxxxxx>
Signed-off-by: Greg Kroah-Hartman <gregkh@xxxxxxxxxxxxxxxxxxx>

Reviewed-by: Matthias Maennich <maennich@xxxxxxxxxx>

Cheers,
Matthias

---
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(-)

diff --git a/include/linux/export.h b/include/linux/export.h
index 27d848712b90..9a992809f57d 100644
--- a/include/linux/export.h
+++ b/include/linux/export.h
@@ -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__ */

--
2.34.1