* [PATCH] add utsname_set_field to reuse code in setdomainname and sethostname
@ 2026-11-05 12:07 Laurijssen
2026-11-06 15:56 ` kernel test robot
2026-11-06 16:31 ` kernel test robot
0 siblings, 2 replies; 3+ messages in thread
From: Laurijssen @ 2026-11-05 12:07 UTC (permalink / raw)
To: linux-kernel, pjw, akpm, jannh, brauner; +Cc: Laurijssen
- add utsname_set_field to utsname_sysctl.c, it reuses duplicated code
- call utsname_set_field from sethostname/setdomainname
- moved uts_proc_notify from .h into utsname_sysctl.c and turned static
Signed-off-by: Laurijssen <laurijssen@protonmail.com>
---
include/linux/utsname.h | 10 ++----
kernel/sys.c | 46 ++-----------------------
kernel/utsname_sysctl.c | 75 ++++++++++++++++++++++++++++++++++-------
3 files changed, 66 insertions(+), 65 deletions(-)
diff --git a/include/linux/utsname.h b/include/linux/utsname.h
index dc5594ffffcc..409261d5381f 100644
--- a/include/linux/utsname.h
+++ b/include/linux/utsname.h
@@ -18,14 +18,6 @@ enum uts_proc {
UTS_PROC_DOMAINNAME,
};
-#ifdef CONFIG_SYSCTL
-extern void uts_proc_notify(enum uts_proc proc);
-#else
-static inline void uts_proc_notify(enum uts_proc proc)
-{
-}
-#endif
-
static inline struct new_utsname *utsname(void)
{
return ¤t->nsproxy->uts_ns->name;
@@ -38,4 +30,6 @@ static inline struct new_utsname *init_utsname(void)
extern struct rw_semaphore uts_sem;
+int utsname_set_field(char __user *name, int len, enum uts_proc proc);
+
#endif /* _LINUX_UTSNAME_H */
diff --git a/kernel/sys.c b/kernel/sys.c
index 755bfa5ccd92..688c5e9e222f 100644
--- a/kernel/sys.c
+++ b/kernel/sys.c
@@ -1421,28 +1421,7 @@ SYSCALL_DEFINE1(olduname, struct oldold_utsname __user *, name)
SYSCALL_DEFINE2(sethostname, char __user *, name, int, len)
{
- int errno;
- char tmp[__NEW_UTS_LEN];
-
- if (!ns_capable(current->nsproxy->uts_ns->user_ns, CAP_SYS_ADMIN))
- return -EPERM;
-
- if (len < 0 || len > __NEW_UTS_LEN)
- return -EINVAL;
- errno = -EFAULT;
- if (!copy_from_user(tmp, name, len)) {
- struct new_utsname *u;
-
- add_device_randomness(tmp, len);
- down_write(&uts_sem);
- u = utsname();
- memcpy(u->nodename, tmp, len);
- memset(u->nodename + len, 0, sizeof(u->nodename) - len);
- errno = 0;
- uts_proc_notify(UTS_PROC_HOSTNAME);
- up_write(&uts_sem);
- }
- return errno;
+ return utsname_set_field(name, len, UTS_PROC_HOSTNAME);
}
#ifdef __ARCH_WANT_SYS_GETHOSTNAME
@@ -1475,28 +1454,7 @@ SYSCALL_DEFINE2(gethostname, char __user *, name, int, len)
*/
SYSCALL_DEFINE2(setdomainname, char __user *, name, int, len)
{
- int errno;
- char tmp[__NEW_UTS_LEN];
-
- if (!ns_capable(current->nsproxy->uts_ns->user_ns, CAP_SYS_ADMIN))
- return -EPERM;
- if (len < 0 || len > __NEW_UTS_LEN)
- return -EINVAL;
-
- errno = -EFAULT;
- if (!copy_from_user(tmp, name, len)) {
- struct new_utsname *u;
-
- add_device_randomness(tmp, len);
- down_write(&uts_sem);
- u = utsname();
- memcpy(u->domainname, tmp, len);
- memset(u->domainname + len, 0, sizeof(u->domainname) - len);
- errno = 0;
- uts_proc_notify(UTS_PROC_DOMAINNAME);
- up_write(&uts_sem);
- }
- return errno;
+ return utsname_set_field(name, len, UTS_PROC_DOMAINNAME);
}
/* make sure you are allowed to change @tsk limits before calling this */
diff --git a/kernel/utsname_sysctl.c b/kernel/utsname_sysctl.c
index 6c1522201e39..026e5c877a8b 100644
--- a/kernel/utsname_sysctl.c
+++ b/kernel/utsname_sysctl.c
@@ -5,6 +5,7 @@
* Author: Eric Biederman <ebiederm@xmision.com>
*/
+#include <linux/capability.h>
#include <linux/export.h>
#include <linux/uts.h>
#include <linux/utsname.h>
@@ -12,6 +13,9 @@
#include <linux/sysctl.h>
#include <linux/wait.h>
#include <linux/rwsem.h>
+#include <linux/uaccess.h>
+
+static const struct ctl_table uts_kern_table[];
#ifdef CONFIG_SYSCTL
@@ -67,10 +71,68 @@ static int proc_do_uts_string(const struct ctl_table *table, int write,
return r;
}
+
+/*
+ * Notify userspace about a change in a certain entry of uts_kern_table,
+ * identified by the parameter proc.
+ */
+static void uts_proc_notify(enum uts_proc proc)
+{
+ const struct ctl_table *table = &uts_kern_table[proc];
+
+ proc_sys_poll_notify(table->poll);
+}
#else
#define proc_do_uts_string NULL
+
+static inline void uts_proc_notify(enum uts_proc proc)
+{
+}
#endif
+int utsname_set_field(char __user *name, int len, enum uts_proc proc)
+{
+ int errno;
+ char tmp[__NEW_UTS_LEN];
+
+ if (!ns_capable(current->nsproxy->uts_ns->user_ns, CAP_SYS_ADMIN))
+ return -EPERM;
+
+ if (len < 0 || len > __NEW_UTS_LEN)
+ return -EINVAL;
+ errno = -EFAULT;
+ if (!copy_from_user(tmp, name, len)) {
+ struct new_utsname *u;
+ char *field;
+
+ add_device_randomness(tmp, len);
+ down_write(&uts_sem);
+
+ u = utsname();
+
+ switch (proc) {
+ case UTS_PROC_HOSTNAME:
+ field = u->nodename;
+ break;
+ case UTS_PROC_DOMAINNAME:
+ field = u->domainname;
+ break;
+ default:
+ WARN_ON_ONCE(1);
+ field = u->domainname;
+ break;
+ }
+
+ memcpy(field, tmp, len);
+ memset(field + len, 0, sizeof_field(struct new_utsname, nodename) - len);
+
+ errno = 0;
+ uts_proc_notify(proc);
+ up_write(&uts_sem);
+ }
+ return errno;
+}
+
static DEFINE_CTL_TABLE_POLL(hostname_poll);
static DEFINE_CTL_TABLE_POLL(domainname_poll);
@@ -122,19 +184,6 @@ static const struct ctl_table uts_kern_table[] = {
},
};
-#ifdef CONFIG_SYSCTL
-/*
- * Notify userspace about a change in a certain entry of uts_kern_table,
- * identified by the parameter proc.
- */
-void uts_proc_notify(enum uts_proc proc)
-{
- const struct ctl_table *table = &uts_kern_table[proc];
-
- proc_sys_poll_notify(table->poll);
-}
-#endif
-
static int __init utsname_sysctl_init(void)
{
register_sysctl("kernel", uts_kern_table);
--
2.53.0
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] add utsname_set_field to reuse code in setdomainname and sethostname
2026-11-05 12:07 [PATCH] add utsname_set_field to reuse code in setdomainname and sethostname Laurijssen
@ 2026-11-06 15:56 ` kernel test robot
2026-11-06 16:31 ` kernel test robot
1 sibling, 0 replies; 3+ messages in thread
From: kernel test robot @ 2026-11-06 15:56 UTC (permalink / raw)
To: Laurijssen, linux-kernel, pjw, akpm, jannh, brauner
Cc: oe-kbuild-all, Laurijssen
Hi Laurijssen,
kernel test robot noticed the following build errors:
[auto build test ERROR on akpm-mm/mm-everything]
[also build test ERROR on brauner-vfs/vfs.all linus/master v7.4-rc1 next-20261105]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Laurijssen/add-utsname_set_field-to-reuse-code-in-setdomainname-and-sethostname/20261105-130751
base: https://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm.git mm-everything
patch link: https://lore.kernel.org/r/20261105120751.920311-1-laurijssen%40protonmail.com
patch subject: [PATCH] add utsname_set_field to reuse code in setdomainname and sethostname
config: sh-randconfig-1000-20261106 (https://download.01.org/0day-ci/archive/20261106/202611062313.QD6BbpXI-lkp@intel.com/config)
compiler: sh4-linux-gcc (GCC) 11.5.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20261106/202611062313.QD6BbpXI-lkp@intel.com/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202611062313.QD6BbpXI-lkp@intel.com/
All errors (new ones prefixed by >>):
sh4-linux-ld: kernel/sys.o: in function `__se_sys_sethostname':
>> kernel/sys.c:1422:(.text+0x3d5c): undefined reference to `utsname_set_field'
sh4-linux-ld: kernel/sys.o: in function `__se_sys_setdomainname':
kernel/sys.c:1455:(.text+0x3edc): undefined reference to `utsname_set_field'
vim +1422 kernel/sys.c
5cacdb4add1b1e5 Christoph Hellwig 2010-03-10 1421
5a8a82b1d306a32 Heiko Carstens 2009-01-14 @1422 SYSCALL_DEFINE2(sethostname, char __user *, name, int, len)
^1da177e4c3f415 Linus Torvalds 2005-04-16 1423 {
58c79d6f0053050 Laurijssen 2026-11-05 1424 return utsname_set_field(name, len, UTS_PROC_HOSTNAME);
^1da177e4c3f415 Linus Torvalds 2005-04-16 1425 }
^1da177e4c3f415 Linus Torvalds 2005-04-16 1426
--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] add utsname_set_field to reuse code in setdomainname and sethostname
2026-11-05 12:07 [PATCH] add utsname_set_field to reuse code in setdomainname and sethostname Laurijssen
2026-11-06 15:56 ` kernel test robot
@ 2026-11-06 16:31 ` kernel test robot
1 sibling, 0 replies; 3+ messages in thread
From: kernel test robot @ 2026-11-06 16:31 UTC (permalink / raw)
To: Laurijssen, linux-kernel, pjw, akpm, jannh, brauner
Cc: llvm, oe-kbuild-all, Laurijssen
Hi Laurijssen,
kernel test robot noticed the following build errors:
[auto build test ERROR on akpm-mm/mm-everything]
[also build test ERROR on brauner-vfs/vfs.all linus/master v7.4-rc1 next-20261105]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Laurijssen/add-utsname_set_field-to-reuse-code-in-setdomainname-and-sethostname/20261105-130751
base: https://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm.git mm-everything
patch link: https://lore.kernel.org/r/20261105120751.920311-1-laurijssen%40protonmail.com
patch subject: [PATCH] add utsname_set_field to reuse code in setdomainname and sethostname
config: riscv-randconfig-1001-20261106 (https://download.01.org/0day-ci/archive/20261107/202611070006.O8jXXb72-lkp@intel.com/config)
compiler: clang version 20.1.8 (https://github.com/llvm/llvm-project 87f0227cb60147a26a1eeb4fb06e3b505e9c7261)
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20261107/202611070006.O8jXXb72-lkp@intel.com/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202611070006.O8jXXb72-lkp@intel.com/
All errors (new ones prefixed by >>):
>> ld.lld: error: undefined symbol: utsname_set_field
>>> referenced by sys.c:1424 (kernel/sys.c:1424)
>>> vmlinux.o:(___se_sys_sethostname)
>>> referenced by sys.c:1457 (kernel/sys.c:1457)
>>> vmlinux.o:(___se_sys_setdomainname)
--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-11-06 16:32 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-05 12:07 [PATCH] add utsname_set_field to reuse code in setdomainname and sethostname Laurijssen
2026-11-06 15:56 ` kernel test robot
2026-11-06 16:31 ` kernel test robot
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®