Commit 91b6163b authored by Linus Torvalds's avatar Linus Torvalds
Browse files
Pull sysctl updates from Joel Granados:

 - Remove sentinel elements from ctl_table structs in kernel/*

   Removing sentinels in ctl_table arrays reduces the build time size
   and runtime memory consumed by ~64 bytes per array. Removals for
   net/, io_uring/, mm/, ipc/ and security/ are set to go into mainline
   through their respective subsystems making the next release the most
   likely place where the final series that removes the check for
   proc_name == NULL will land.

   This adds to removals already in arch/, drivers/ and fs/.

 - Adjust ctl_table definitions and references to allow constification
     - Remove unused ctl_table function arguments
     - Move non-const elements from ctl_table to ctl_table_header
     - Make ctl_table pointers const in ctl_table_root structure

   Making the static ctl_table structs const will increase safety by
   keeping the pointers to proc_handler functions in .rodata. Though no
   ctl_tables where made const in this PR, the ground work for making
   that possible has started with these changes sent by Thomas
   Weißschuh.

* tag 'sysctl-6.10-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/sysctl/sysctl:
  sysctl: drop now unnecessary out-of-bounds check
  sysctl: move sysctl type to ctl_table_header
  sysctl: drop sysctl_is_perm_empty_ctl_table
  sysctl: treewide: constify argument ctl_table_root::permissions(table)
  sysctl: treewide: drop unused argument ctl_table_root::set_ownership(table)
  bpf: Remove the now superfluous sentinel elements from ctl_table array
  delayacct: Remove the now superfluous sentinel elements from ctl_table array
  kprobes: Remove the now superfluous sentinel elements from ctl_table array
  printk: Remove the now superfluous sentinel elements from ctl_table array
  scheduler: Remove the now superfluous sentinel elements from ctl_table array
  seccomp: Remove the now superfluous sentinel elements from ctl_table array
  timekeeping: Remove the now superfluous sentinel elements from ctl_table array
  ftrace: Remove the now superfluous sentinel elements from ctl_table array
  umh: Remove the now superfluous sentinel elements from ctl_table array
  kernel misc: Remove the now superfluous sentinel elements from ctl_table array
parents 06f054b1 a35dd3a7
Loading
Loading
Loading
Loading
+9 −12
Original line number Diff line number Diff line
@@ -30,9 +30,7 @@ static const struct file_operations proc_sys_dir_file_operations;
static const struct inode_operations proc_sys_dir_operations;

/* Support for permanently empty directories */
static struct ctl_table sysctl_mount_point[] = {
	{.type = SYSCTL_TABLE_TYPE_PERMANENTLY_EMPTY }
};
static struct ctl_table sysctl_mount_point[] = { };

/**
 * register_sysctl_mount_point() - registers a sysctl mount point
@@ -48,14 +46,12 @@ struct ctl_table_header *register_sysctl_mount_point(const char *path)
}
EXPORT_SYMBOL(register_sysctl_mount_point);

#define sysctl_is_perm_empty_ctl_table(tptr)		\
	(tptr[0].type == SYSCTL_TABLE_TYPE_PERMANENTLY_EMPTY)
#define sysctl_is_perm_empty_ctl_header(hptr)		\
	(sysctl_is_perm_empty_ctl_table(hptr->ctl_table))
	(hptr->type == SYSCTL_TABLE_TYPE_PERMANENTLY_EMPTY)
#define sysctl_set_perm_empty_ctl_header(hptr)		\
	(hptr->ctl_table[0].type = SYSCTL_TABLE_TYPE_PERMANENTLY_EMPTY)
	(hptr->type = SYSCTL_TABLE_TYPE_PERMANENTLY_EMPTY)
#define sysctl_clear_perm_empty_ctl_header(hptr)	\
	(hptr->ctl_table[0].type = SYSCTL_TABLE_TYPE_DEFAULT)
	(hptr->type = SYSCTL_TABLE_TYPE_DEFAULT)

void proc_sys_poll_notify(struct ctl_table_poll *poll)
{
@@ -210,6 +206,8 @@ static void init_header(struct ctl_table_header *head,
			node++;
		}
	}
	if (table == sysctl_mount_point)
		sysctl_set_perm_empty_ctl_header(head);
}

static void erase_header(struct ctl_table_header *head)
@@ -232,8 +230,7 @@ static int insert_header(struct ctl_dir *dir, struct ctl_table_header *header)
		return -EROFS;

	/* Am I creating a permanently empty directory? */
	if (header->ctl_table_size > 0 &&
	    sysctl_is_perm_empty_ctl_table(header->ctl_table)) {
	if (sysctl_is_perm_empty_ctl_header(header)) {
		if (!RB_EMPTY_ROOT(&dir->root))
			return -EINVAL;
		sysctl_set_perm_empty_ctl_header(dir_h);
@@ -480,7 +477,7 @@ static struct inode *proc_sys_make_inode(struct super_block *sb,
	}

	if (root->set_ownership)
		root->set_ownership(head, table, &inode->i_uid, &inode->i_gid);
		root->set_ownership(head, &inode->i_uid, &inode->i_gid);
	else {
		inode->i_uid = GLOBAL_ROOT_UID;
		inode->i_gid = GLOBAL_ROOT_GID;
@@ -1204,7 +1201,7 @@ static bool get_links(struct ctl_dir *dir,
	struct ctl_table *entry, *link;

	if (header->ctl_table_size == 0 ||
	    sysctl_is_perm_empty_ctl_table(header->ctl_table))
	    sysctl_is_perm_empty_ctl_header(header))
		return true;

	/* Are there links available for every entry in table? */
+12 −13
Original line number Diff line number Diff line
@@ -137,17 +137,6 @@ struct ctl_table {
	void *data;
	int maxlen;
	umode_t mode;
	/**
	 * enum type - Enumeration to differentiate between ctl target types
	 * @SYSCTL_TABLE_TYPE_DEFAULT: ctl target with no special considerations
	 * @SYSCTL_TABLE_TYPE_PERMANENTLY_EMPTY: Used to identify a permanently
	 *                                       empty directory target to serve
	 *                                       as mount point.
	 */
	enum {
		SYSCTL_TABLE_TYPE_DEFAULT,
		SYSCTL_TABLE_TYPE_PERMANENTLY_EMPTY
	} type;
	proc_handler *proc_handler;	/* Callback for text formatting */
	struct ctl_table_poll *poll;
	void *extra1;
@@ -188,6 +177,17 @@ struct ctl_table_header {
	struct ctl_dir *parent;
	struct ctl_node *node;
	struct hlist_head inodes; /* head for proc_inode->sysctl_inodes */
	/**
	 * enum type - Enumeration to differentiate between ctl target types
	 * @SYSCTL_TABLE_TYPE_DEFAULT: ctl target with no special considerations
	 * @SYSCTL_TABLE_TYPE_PERMANENTLY_EMPTY: Used to identify a permanently
	 *                                       empty directory target to serve
	 *                                       as mount point.
	 */
	enum {
		SYSCTL_TABLE_TYPE_DEFAULT,
		SYSCTL_TABLE_TYPE_PERMANENTLY_EMPTY,
	} type;
};

struct ctl_dir {
@@ -205,9 +205,8 @@ struct ctl_table_root {
	struct ctl_table_set default_set;
	struct ctl_table_set *(*lookup)(struct ctl_table_root *root);
	void (*set_ownership)(struct ctl_table_header *head,
			      struct ctl_table *table,
			      kuid_t *uid, kgid_t *gid);
	int (*permissions)(struct ctl_table_header *head, struct ctl_table *table);
	int (*permissions)(struct ctl_table_header *head, const struct ctl_table *table);
};

#define register_sysctl(path, table)	\
+2 −3
Original line number Diff line number Diff line
@@ -192,7 +192,6 @@ static int set_is_seen(struct ctl_table_set *set)
}

static void ipc_set_ownership(struct ctl_table_header *head,
			      struct ctl_table *table,
			      kuid_t *uid, kgid_t *gid)
{
	struct ipc_namespace *ns =
@@ -205,7 +204,7 @@ static void ipc_set_ownership(struct ctl_table_header *head,
	*gid = gid_valid(ns_root_gid) ? ns_root_gid : GLOBAL_ROOT_GID;
}

static int ipc_permissions(struct ctl_table_header *head, struct ctl_table *table)
static int ipc_permissions(struct ctl_table_header *head, const struct ctl_table *table)
{
	int mode = table->mode;

@@ -224,7 +223,7 @@ static int ipc_permissions(struct ctl_table_header *head, struct ctl_table *tabl
		kuid_t ns_root_uid;
		kgid_t ns_root_gid;

		ipc_set_ownership(head, table, &ns_root_uid, &ns_root_gid);
		ipc_set_ownership(head, &ns_root_uid, &ns_root_gid);

		if (uid_eq(current_euid(), ns_root_uid))
			mode >>= 6;
+2 −3
Original line number Diff line number Diff line
@@ -78,7 +78,6 @@ static int set_is_seen(struct ctl_table_set *set)
}

static void mq_set_ownership(struct ctl_table_header *head,
			     struct ctl_table *table,
			     kuid_t *uid, kgid_t *gid)
{
	struct ipc_namespace *ns =
@@ -91,13 +90,13 @@ static void mq_set_ownership(struct ctl_table_header *head,
	*gid = gid_valid(ns_root_gid) ? ns_root_gid : GLOBAL_ROOT_GID;
}

static int mq_permissions(struct ctl_table_header *head, struct ctl_table *table)
static int mq_permissions(struct ctl_table_header *head, const struct ctl_table *table)
{
	int mode = table->mode;
	kuid_t ns_root_uid;
	kgid_t ns_root_gid;

	mq_set_ownership(head, table, &ns_root_uid, &ns_root_gid);
	mq_set_ownership(head, &ns_root_uid, &ns_root_gid);

	if (uid_eq(current_euid(), ns_root_uid))
		mode >>= 6;
+0 −1
Original line number Diff line number Diff line
@@ -84,7 +84,6 @@ static struct ctl_table kern_acct_table[] = {
		.mode           = 0644,
		.proc_handler   = proc_dointvec,
	},
	{ }
};

static __init int kernel_acct_sysctls_init(void)
Loading