From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pl1-f169.google.com (mail-pl1-f169.google.com [209.85.214.169]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C86C5348453 for ; Thu, 5 Mar 2026 22:32:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.169 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772749972; cv=none; b=n0b/WLkFlwdJ7qrSjK2NJ7gBbCV1JwOQrCycunMDn8mzoWOLOYAW87Mi+fMOZQ9c+fQpDBusv78gFqRyK15y/2e3TibQLICK9OnYpnT3l5bNLTIyyNZGZUc0TE9qD6QTPtA32uwbrgJ4mGYndXTbulM4aYHbVdKGu8PJiPxVXEU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772749972; c=relaxed/simple; bh=MglYxuye+f6mi7DlYbR0pjhnIPwFYCOCLfH+Kswlkm0=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=BwW+CsalOi8mbjYEdTOAvrKG9OfjPI+pFaG9RNCbP0dNsIYTlml/02YIcOububfn4wACL3IT55YxAJPVyYCbCSGc/URK31B02KoycCE9HGyvDhP6o6tm9FfiV18AqUox0m8/0sM6fJ9hsd0FpQqMB7hyOdN7TV9ZWgT7Qc2xnrU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=qolQ047o; arc=none smtp.client-ip=209.85.214.169 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="qolQ047o" Received: by mail-pl1-f169.google.com with SMTP id d9443c01a7336-2ae49120e97so27315ad.0 for ; Thu, 05 Mar 2026 14:32:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1772749971; x=1773354771; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=n7dtkvH98TyYtXXMGFbwc3ykk2Hwk5qV14QGB+DUa00=; b=qolQ047oER3xWZChKug56AJRSYSyFzFCX9BFa3Jc/OQmd9lFCdjrzsrZcn+gaTaam1 rDKQVFxhRPwRRCZRi0iCbg0MhTqyIN21cd6CPLbN8uduyoDTQxZ9Henb/xPOo9vwMuh6 AWYqeC9JfTZr/JVag3X6rx+kaTkklteJyC2x3MTiac0qOKvQzmeyO4CdQTwrPQgEm38n JQn06Ndn41CfFJ/BBX7CNN+Us7om7I7IWLH8CPYSVriVokMNklIDUB6IXB13/1xgfyRo G4EyUsDohH0iZWF1WZ5U5OZ3LZPh6WgShM5r3MBAyvV5bOsV5hT/Ec55QPrV8hVYwbof +lGg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1772749971; x=1773354771; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-gg:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=n7dtkvH98TyYtXXMGFbwc3ykk2Hwk5qV14QGB+DUa00=; b=ASqG0NdBnvBMrtRHGmCWywABKs+DNkFo5NjBX26rRczoVcY7osOucYIH6itNUAXK86 nCHwJFjZY1EJlRM6d4NVylCLOTGc06+JMvP1g2YnYPornQe5zoPXlpbGagV37psIFfTU eGwttWkBvLPL9FEdD5EEIMwhX3KODUwU0xSO8LZEf0Xw6O/Udyk6v7+ILfdL+VXZ6hB3 d4nVEMn1cxSE6MAHRmULvuHNrEOJKMXTTT0T6TfLtqwT7e6qY+XZuAo9vtjRxV+8SEzg pY3X1qH1nHEXNKrjIBxpDuRHG6K/kVpzqvxWRbeYKLXN15bPnHBe0X51QmsN1Td62UO/ K+SQ== X-Forwarded-Encrypted: i=1; AJvYcCXneYERVkNO16JKIqcCSK6nPreYWRhwc8QLbe3fnP1k7Ik4Uaxcippkw5SPQf7MN/SKq2UMPsPqZUEhP2o=@vger.kernel.org X-Gm-Message-State: AOJu0YyFYDtxLpgEgh0/pL1V51Shpr8pL7SBXnCQEryg2ZOeRXOgbl+S ArH8IktLE8et8fBfFd4uy2ze+Fzk7ue639+BwPIhCx1PfwQtC6mfDWer+FPEy/tFvg== X-Gm-Gg: ATEYQzwR36l52XlgyVf3e4a5x5AdzT0qTU8MvjoSKijdpJXUQ8z2dBzlJsGhrprGjNV 48an/Cl2TMTKu7qcdyjBKS/pZC6QCOhIj5Fp/WV7KcPRdzQiF9WS+MQ18yDeVEA9PWVcVEciTWg f5oC4/6svp7jdSgv6cquw++IVWRydfVyu9mbnxd7ntZV64Vlmjvd9NzWtB+T2DzgB2MfsQrZWQ7 M6Li/LdqCo2sC26+Z0+wNj7124XNfLO7jwWNp7btCojt3TgHv9MUz9c0zKUAW66rd84r1dP0PEg PKrts08rseUxKdPfZWIbvu+x87RFS1sowgBvKQRdlNKxUiilkj1JvtOr6+cQdhJhQK2bw8neqGg Fr57d6q7v8732+it/Z0TPWE4iQjzj/lZo+aAB4OZLx9nRL3eiFf0GzX+/44kxDiDO175/7g1Ogh r29Ocyr3HgTdZ7OiCHAvumn4Y+LmdmwalRX1mJ6kOvPQ1k6XRJ+PnAUAer5sRN2uqZOC4= X-Received: by 2002:a17:903:f90:b0:2ae:6432:8f77 with SMTP id d9443c01a7336-2ae81e8c6ffmr394105ad.17.1772749970601; Thu, 05 Mar 2026 14:32:50 -0800 (PST) Received: from google.com (197.23.125.34.bc.googleusercontent.com. [34.125.23.197]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-829751f3867sm5267441b3a.55.2026.03.05.14.32.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Mar 2026 14:32:49 -0800 (PST) Date: Thu, 5 Mar 2026 22:32:45 +0000 From: Sami Tolvanen To: Nicholas Sielicki Cc: Luis Chamberlain , Petr Pavlu , Daniel Gomez , Aaron Tomlin , Matthias Maennich , Peter Zijlstra , Jonathan Corbet , Randy Dunlap , linux-modules@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH 1/2] module: expose imported namespaces via sysfs Message-ID: <20260305223245.GA732271@google.com> References: <20260108044710.33036-1-linux@opensource.nslick.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20260108044710.33036-1-linux@opensource.nslick.com> On Wed, Jan 07, 2026 at 10:47:09PM -0600, Nicholas Sielicki wrote: > > +static ssize_t show_modinfo_import_ns(const struct module_attribute *mattr, > + struct module_kobject *mk, char *buffer) > +{ > + return sysfs_emit(buffer, "%s\n", mk->mod->imported_namespaces); > +} > + > +static int modinfo_import_ns_exists(struct module *mod) > +{ > + return mod->imported_namespaces != NULL; > +} > + > +static const struct module_attribute modinfo_import_ns = { > + .attr = { .name = "import_ns", .mode = 0444 }, > + .show = show_modinfo_import_ns, > + .test = modinfo_import_ns_exists, > +}; > + Don't we need a .setup function that initializes mod->imported_namespaces to NULL? Currently, if setup_modinfo returns an error, the pointer remains initialized to whatever value we read from .gnu.linkonce.this_module, and we'll pass that arbitrary pointer to kfree. This isn't normally a problem since modpost zero-initializes the field, but we don't want to rely on userspace to initialize our pointers. Also, define .free to release the buffer instead of adding a direct call to free_modinfo. > static struct { > char name[MODULE_NAME_LEN]; > char taints[MODULE_FLAGS_BUF_SIZE]; > @@ -1058,6 +1075,7 @@ const struct module_attribute *const modinfo_attrs[] = { > &module_uevent, > &modinfo_version, > &modinfo_srcversion, > + &modinfo_import_ns, > &modinfo_initstate, > &modinfo_coresize, > #ifdef CONFIG_ARCH_WANTS_MODULES_DATA_IN_VMALLOC > @@ -1753,11 +1771,48 @@ static void module_license_taint_check(struct module *mod, const char *license) > } > } > > +static int copy_modinfo_import_ns(struct module *mod, struct load_info *info) > +{ > + char *ns; > + size_t len, total_len = 0; > + char *buf, *p; > + > + for_each_modinfo_entry(ns, info, "import_ns") > + total_len += strlen(ns) + 1; > + > + if (!total_len) { > + mod->imported_namespaces = NULL; > + return 0; > + } > + > + buf = kmalloc(total_len, GFP_KERNEL); > + if (!buf) > + return -ENOMEM; For example, if kmalloc fails, mod->imported_namespaces isn't initialized. > + > + p = buf; > + for_each_modinfo_entry(ns, info, "import_ns") { > + len = strlen(ns); > + memcpy(p, ns, len); > + p += len; > + *p++ = '\n'; > + } > + /* Replace trailing newline with null terminator. */ > + *(p - 1) = '\0'; > + > + mod->imported_namespaces = buf; > + return 0; > +} > + > +static void free_modinfo_import_ns(struct module *mod) > +{ > + kfree(mod->imported_namespaces); mod->imported_namespaces = NULL; > +} > + > static int setup_modinfo(struct module *mod, struct load_info *info) > { > const struct module_attribute *attr; > char *imported_namespace; > - int i; > + int i, err; > > for (i = 0; (attr = modinfo_attrs[i]); i++) { > if (attr->setup) > @@ -1776,6 +1831,10 @@ static int setup_modinfo(struct module *mod, struct load_info *info) > } > } Also setup_modinfo can fail before copy_modinfo_import_ns is even called. > + err = copy_modinfo_import_ns(mod, info); > + if (err) > + return err; > + Sami