2121
2222#define list_for_each_table_entry (entry , header ) \
2323 entry = header->ctl_table; \
24- for (size_t i = 0 ; i < header->ctl_table_size && entry->procname ; ++i, entry++)
24+ for (size_t i = 0 ; i < header->ctl_table_size; ++i, entry++)
2525
2626static const struct dentry_operations proc_sys_dentry_operations ;
2727static const struct file_operations proc_sys_file_operations ;
@@ -476,12 +476,10 @@ static struct inode *proc_sys_make_inode(struct super_block *sb,
476476 make_empty_dir_inode (inode );
477477 }
478478
479+ inode -> i_uid = GLOBAL_ROOT_UID ;
480+ inode -> i_gid = GLOBAL_ROOT_GID ;
479481 if (root -> set_ownership )
480482 root -> set_ownership (head , & inode -> i_uid , & inode -> i_gid );
481- else {
482- inode -> i_uid = GLOBAL_ROOT_UID ;
483- inode -> i_gid = GLOBAL_ROOT_GID ;
484- }
485483
486484 return inode ;
487485}
@@ -951,14 +949,14 @@ static struct ctl_dir *new_dir(struct ctl_table_set *set,
951949 char * new_name ;
952950
953951 new = kzalloc (sizeof (* new ) + sizeof (struct ctl_node ) +
954- sizeof (struct ctl_table )* 2 + namelen + 1 ,
952+ sizeof (struct ctl_table ) + namelen + 1 ,
955953 GFP_KERNEL );
956954 if (!new )
957955 return NULL ;
958956
959957 node = (struct ctl_node * )(new + 1 );
960958 table = (struct ctl_table * )(node + 1 );
961- new_name = (char * )(table + 2 );
959+ new_name = (char * )(table + 1 );
962960 memcpy (new_name , name , namelen );
963961 table [0 ].procname = new_name ;
964962 table [0 ].mode = S_IFDIR |S_IRUGO |S_IXUGO ;
@@ -1093,6 +1091,7 @@ static int sysctl_err(const char *path, struct ctl_table *table, char *fmt, ...)
10931091
10941092static int sysctl_check_table_array (const char * path , struct ctl_table * table )
10951093{
1094+ unsigned int extra ;
10961095 int err = 0 ;
10971096
10981097 if ((table -> proc_handler == proc_douintvec ) ||
@@ -1104,6 +1103,19 @@ static int sysctl_check_table_array(const char *path, struct ctl_table *table)
11041103 if (table -> proc_handler == proc_dou8vec_minmax ) {
11051104 if (table -> maxlen != sizeof (u8 ))
11061105 err |= sysctl_err (path , table , "array not allowed" );
1106+
1107+ if (table -> extra1 ) {
1108+ extra = * (unsigned int * ) table -> extra1 ;
1109+ if (extra > 255U )
1110+ err |= sysctl_err (path , table ,
1111+ "range value too large for proc_dou8vec_minmax" );
1112+ }
1113+ if (table -> extra2 ) {
1114+ extra = * (unsigned int * ) table -> extra2 ;
1115+ if (extra > 255U )
1116+ err |= sysctl_err (path , table ,
1117+ "range value too large for proc_dou8vec_minmax" );
1118+ }
11071119 }
11081120
11091121 if (table -> proc_handler == proc_dobool ) {
@@ -1119,6 +1131,8 @@ static int sysctl_check_table(const char *path, struct ctl_table_header *header)
11191131 struct ctl_table * entry ;
11201132 int err = 0 ;
11211133 list_for_each_table_entry (entry , header ) {
1134+ if (!entry -> procname )
1135+ err |= sysctl_err (path , entry , "procname is null" );
11221136 if ((entry -> proc_handler == proc_dostring ) ||
11231137 (entry -> proc_handler == proc_dobool ) ||
11241138 (entry -> proc_handler == proc_dointvec ) ||
@@ -1154,27 +1168,25 @@ static struct ctl_table_header *new_links(struct ctl_dir *dir, struct ctl_table_
11541168 struct ctl_table_header * links ;
11551169 struct ctl_node * node ;
11561170 char * link_name ;
1157- int nr_entries , name_bytes ;
1171+ int name_bytes ;
11581172
11591173 name_bytes = 0 ;
1160- nr_entries = 0 ;
11611174 list_for_each_table_entry (entry , head ) {
1162- nr_entries ++ ;
11631175 name_bytes += strlen (entry -> procname ) + 1 ;
11641176 }
11651177
11661178 links = kzalloc (sizeof (struct ctl_table_header ) +
1167- sizeof (struct ctl_node )* nr_entries +
1168- sizeof (struct ctl_table )* ( nr_entries + 1 ) +
1179+ sizeof (struct ctl_node )* head -> ctl_table_size +
1180+ sizeof (struct ctl_table )* head -> ctl_table_size +
11691181 name_bytes ,
11701182 GFP_KERNEL );
11711183
11721184 if (!links )
11731185 return NULL ;
11741186
11751187 node = (struct ctl_node * )(links + 1 );
1176- link_table = (struct ctl_table * )(node + nr_entries );
1177- link_name = (char * )& link_table [ nr_entries + 1 ] ;
1188+ link_table = (struct ctl_table * )(node + head -> ctl_table_size );
1189+ link_name = (char * )( link_table + head -> ctl_table_size ) ;
11781190 link = link_table ;
11791191
11801192 list_for_each_table_entry (entry , head ) {
@@ -1188,7 +1200,7 @@ static struct ctl_table_header *new_links(struct ctl_dir *dir, struct ctl_table_
11881200 }
11891201 init_header (links , dir -> header .root , dir -> header .set , node , link_table ,
11901202 head -> ctl_table_size );
1191- links -> nreg = nr_entries ;
1203+ links -> nreg = head -> ctl_table_size ;
11921204
11931205 return links ;
11941206}
@@ -1300,37 +1312,31 @@ static struct ctl_dir *sysctl_mkdir_p(struct ctl_dir *dir, const char *path)
13001312 * __register_sysctl_table - register a leaf sysctl table
13011313 * @set: Sysctl tree to register on
13021314 * @path: The path to the directory the sysctl table is in.
1303- * @table: the top-level table structure without any child. This table
1304- * should not be free'd after registration. So it should not be
1305- * used on stack. It can either be a global or dynamically allocated
1306- * by the caller and free'd later after sysctl unregistration.
1315+ *
1316+ * @table: the top-level table structure. This table should not be free'd
1317+ * after registration. So it should not be used on stack. It can either
1318+ * be a global or dynamically allocated by the caller and free'd later
1319+ * after sysctl unregistration.
13071320 * @table_size : The number of elements in table
13081321 *
13091322 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1310- * array. A completely 0 filled entry terminates the table.
1323+ * array.
13111324 *
13121325 * The members of the &struct ctl_table structure are used as follows:
1313- *
13141326 * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not
13151327 * enter a sysctl file
1316- *
1317- * data - a pointer to data for use by proc_handler
1318- *
1319- * maxlen - the maximum size in bytes of the data
1320- *
1321- * mode - the file permissions for the /proc/sys file
1322- *
1323- * child - must be %NULL.
1324- *
1328+ * data - a pointer to data for use by proc_handler
1329+ * maxlen - the maximum size in bytes of the data
1330+ * mode - the file permissions for the /proc/sys file
1331+ * type - Defines the target type (described in struct definition)
13251332 * proc_handler - the text handler routine (described below)
13261333 *
13271334 * extra1, extra2 - extra pointers usable by the proc handler routines
13281335 * XXX: we should eventually modify these to use long min / max [0]
13291336 * [0] https://lkml.kernel.org/87zgpte9o4.fsf@email.froward.int.ebiederm.org
13301337 *
13311338 * Leaf nodes in the sysctl tree will be represented by a single file
1332- * under /proc; non-leaf nodes (where child is not NULL) are not allowed,
1333- * sysctl_check_table() verifies this.
1339+ * under /proc; non-leaf nodes are not allowed.
13341340 *
13351341 * There must be a proc_handler routine for any terminal nodes.
13361342 * Several default handlers are available to cover common cases -
0 commit comments