Skip to contentSkip to conversation

hugetlbfs: publish HUGETLBFS_MAGIC via linux/magic.h

PATCH In review nick black 2 participants 5 messages Jun 29, 2009

Subsystems (5)
lore
Share & tools
lore

nick black

author
#0 lore raw

PATCH 1/1 hugetlbfs: publish HUGETLBFS_MAGIC via linux/magic.h

statfs(2)'s man page (release 3.21) lists HUGETLBFS_MAGIC among the other constants, as one would expect. It's not actually exported, though; it's buried within inode.c in fs/hugetlbfs/ (iirc, the kvm userland code has cut-and-pasted the definition into their sources). This patch brings the exported interface into conformance with documentation, is necessary for [f]statfs(2)-based verification of hugetlbfs mounts, and eliminates a duplicate definition of TMPFS_MAGIC floating around in smack_lsm.c.

This is against 2.6.30-rc1. --rigorously, nick

fs/hugetlbfs/inode.c +1 -3
diff -uprN -X linux-2.6.31-rc1-pristine/Documentation/dontdiff linux-2.6.31-rc1-pristine/fs/hugetlbfs/inode.c linux-2.6.31-rc1/fs/hugetlbfs/inode.c
@@ -31,12 +31,10 @@
 #include <linux/statfs.h>
 #include <linux/security.h>
 #include <linux/ima.h>
+#include <linux/magic.h>
 
 #include <asm/uaccess.h>
 
-/* some random number */
-#define HUGETLBFS_MAGIC	0x958458f6
-
 static const struct super_operations hugetlbfs_ops;
 static const struct address_space_operations hugetlbfs_aops;
 const struct file_operations hugetlbfs_file_operations;
include/linux/magic.h +1 -0
diff -uprN -X linux-2.6.31-rc1-pristine/Documentation/dontdiff linux-2.6.31-rc1-pristine/include/linux/magic.h linux-2.6.31-rc1/include/linux/magic.h
@@ -13,6 +13,7 @@
 #define SECURITYFS_MAGIC	0x73636673
 #define SELINUX_MAGIC		0xf97cff8c
 #define TMPFS_MAGIC		0x01021994
+#define HUGETLBFS_MAGIC 	0x958458f6	/* some random number */
 #define SQUASHFS_MAGIC		0x73717368
 #define EFS_SUPER_MAGIC		0x414A53
 #define EXT2_SUPER_MAGIC	0xEF53
security/smack/smack_lsm.c +1 -1
diff -uprN -X linux-2.6.31-rc1-pristine/Documentation/dontdiff linux-2.6.31-rc1-pristine/security/smack/smack_lsm.c linux-2.6.31-rc1/security/smack/smack_lsm.c
@@ -30,6 +30,7 @@
 #include <net/netlabel.h>
 #include <net/cipso_ipv4.h>
 #include <linux/audit.h>
+#include <linux/magic.h>
 #include "smack.h"
 
 #define task_security(task)	(task_cred_xxx((task), security))
@@ -39,7 +40,6 @@
  */
 #define DEVPTS_SUPER_MAGIC	0x1cd1
 #define SOCKFS_MAGIC		0x534F434B
-#define TMPFS_MAGIC		0x01021994
 
 /**
  * smk_fetch - Fetch the smack label from a file.
Signature · 4 lines
                                      Nick Black <[email protected]>
                                             Principal Engineer, McAfee
                                  Grad student, GT College of Computing
                    "np: the class of dashed hopes, and idle dreams..."
#1 lore raw

Hi Nick,

Quoted 32 lines · nick black

statfs(2)'s man page (release 3.21) lists HUGETLBFS_MAGIC among the other constants, as one would expect. It's not actually exported, though; it's buried within inode.c in fs/hugetlbfs/ (iirc, the kvm userland code has cut-and-pasted the definition into their sources). This patch brings the exported interface into conformance with documentation, is necessary for [f]statfs(2)-based verification of hugetlbfs mounts, and eliminates a duplicate definition of TMPFS_MAGIC floating around in smack_lsm.c.

This is against 2.6.30-rc1. --rigorously, nick

diff -uprN -X linux-2.6.31-rc1-pristine/Documentation/dontdiff linux-2.6.31-rc1-pristine/fs/hugetlbfs/inode.c linux-2.6.31-rc1/fs/hugetlbfs/inode.c

fs/hugetlbfs/inode.c       2009-06-29 07:52:43.000000000 -0400 renamed from fs/hugetlbfs/inode.c      2009-06-24 19:25:37.000000000 -0400 +1 -3
@@ -31,12 +31,10 @@
  #include <linux/statfs.h>
  #include <linux/security.h>
  #include <linux/ima.h>
+#include <linux/magic.h>
 
  #include <asm/uaccess.h>
 
-/* some random number */
-#define HUGETLBFS_MAGIC        0x958458f6
-
  static const struct super_operations hugetlbfs_ops;
  static const struct address_space_operations hugetlbfs_aops;
  const struct file_operations hugetlbfs_file_operations;

diff -uprN -X linux-2.6.31-rc1-pristine/Documentation/dontdiff linux-2.6.31-rc1-pristine/include/linux/magic.h linux-2.6.31-rc1/include/linux/magic.h

include/linux/magic.h      2009-06-29 07:58:15.000000000 -0400 line 19

Quoted 7 lines
include/linux/magic.h      2009-06-29 07:58:15.000000000 -0400 renamed from include/linux/magic.h     2009-06-24 19:25:37.000000000 -0400 +1 -0
@@ -13,6 +13,7 @@
  #define SECURITYFS_MAGIC       0x73636673
  #define SELINUX_MAGIC          0xf97cff8c
  #define TMPFS_MAGIC            0x01021994
+#define HUGETLBFS_MAGIC        0x958458f6      /* some random number */
  #define SQUASHFS_MAGIC         0x73717368
  #define EFS_SUPER_MAGIC                0x414A53
  #define EXT2_SUPER_MAGIC       0xEF53

Looks good to me.

Quoted 12 lines

diff -uprN -X linux-2.6.31-rc1-pristine/Documentation/dontdiff linux-2.6.31-rc1-pristine/security/smack/smack_lsm.c linux-2.6.31-rc1/security/smack/smack_lsm.c

security/smack/smack_lsm.c 2009-06-29 07:54:28.000000000 -0400 renamed from security/smack/smack_lsm.c        2009-06-24 19:25:37.000000000 -0400 +1 -0
@@ -30,6 +30,7 @@
  #include <net/netlabel.h>
  #include <net/cipso_ipv4.h>
  #include <linux/audit.h>
+#include <linux/magic.h>
  #include "smack.h"
 
  #define task_security(task)    (task_cred_xxx((task), security))

security/smack/smack_lsm.c 2009-06-29 07:54:28.000000000 -0400 line 42

Quoted 4 lines
security/smack/smack_lsm.c 2009-06-29 07:54:28.000000000 -0400 renamed from security/smack/smack_lsm.c        2009-06-24 19:25:37.000000000 -0400 +0 -1
@@ -39,7 +40,6 @@
  */
  #define DEVPTS_SUPER_MAGIC     0x1cd1
  #define SOCKFS_MAGIC           0x534F434B
-#define TMPFS_MAGIC            0x01021994

This looks good to me as well but it should be a separate patch as the change has nothing to do with hugetlbfs. While at it, you should probably move SOCKFS_MAGIC and DEVPTS_SUPER_MAGIC to <linux/magic.h> and remove the definitions from smack.

Pekka

author
#2 lore raw

Pekka Enberg left as an exercise for the reader:

Quoted 5 lines

Hi Nick,
This looks good to me as well but it should be a separate patch as the change has nothing to do with hugetlbfs. While at it, you should probably move SOCKFS_MAGIC and DEVPTS_SUPER_MAGIC to <linux/magic.h> and remove the definitions from smack.

Thanks for the review, Pekka, and I couldn't agree more. Here's a second version of the patch, a rather more equal-opportunity unification of magic numbers (I'll resend with a new Subject if that's preferred):

fs/devpts/inode.c +1 -2
diff -uprN -X linux-2.6.31-rc1-pristine/Documentation/dontdiff linux-2.6.31-rc1-pristine/fs/devpts/inode.c linux-2.6.31-rc1/fs/devpts/inode.c
@@ -18,14 +18,13 @@
 #include <linux/mount.h>
 #include <linux/tty.h>
 #include <linux/mutex.h>
+#include <linux/magic.h>
 #include <linux/idr.h>
 #include <linux/devpts_fs.h>
 #include <linux/parser.h>
 #include <linux/fsnotify.h>
 #include <linux/seq_file.h>
 
-#define DEVPTS_SUPER_MAGIC 0x1cd1
-
 #define DEVPTS_DEFAULT_MODE 0600
 /*
  * ptmx is a new node in /dev/pts and will be unused in legacy (single-
fs/hugetlbfs/inode.c +1 -3
diff -uprN -X linux-2.6.31-rc1-pristine/Documentation/dontdiff linux-2.6.31-rc1-pristine/fs/hugetlbfs/inode.c linux-2.6.31-rc1/fs/hugetlbfs/inode.c
@@ -31,12 +31,10 @@
 #include <linux/statfs.h>
 #include <linux/security.h>
 #include <linux/ima.h>
+#include <linux/magic.h>
 
 #include <asm/uaccess.h>
 
-/* some random number */
-#define HUGETLBFS_MAGIC	0x958458f6
-
 static const struct super_operations hugetlbfs_ops;
 static const struct address_space_operations hugetlbfs_aops;
 const struct file_operations hugetlbfs_file_operations;
include/linux/magic.h +5 -0
diff -uprN -X linux-2.6.31-rc1-pristine/Documentation/dontdiff linux-2.6.31-rc1-pristine/include/linux/magic.h linux-2.6.31-rc1/include/linux/magic.h
@@ -13,6 +13,7 @@
 #define SECURITYFS_MAGIC	0x73636673
 #define SELINUX_MAGIC		0xf97cff8c
 #define TMPFS_MAGIC		0x01021994
+#define HUGETLBFS_MAGIC 	0x958458f6	/* some random number */
 #define SQUASHFS_MAGIC		0x73717368
 #define EFS_SUPER_MAGIC		0x414A53
 #define EXT2_SUPER_MAGIC	0xEF53
@@ -53,4 +54,8 @@
 #define INOTIFYFS_SUPER_MAGIC	0x2BAD1DEA
 
 #define STACK_END_MAGIC		0x57AC6E9D
+
+#define DEVPTS_SUPER_MAGIC	0x1cd1
+#define SOCKFS_MAGIC		0x534F434B
+
 #endif /* __LINUX_MAGIC_H__ */
net/socket.c +1 -2
diff -uprN -X linux-2.6.31-rc1-pristine/Documentation/dontdiff linux-2.6.31-rc1-pristine/net/socket.c linux-2.6.31-rc1/net/socket.c
@@ -86,6 +86,7 @@
 #include <linux/audit.h>
 #include <linux/wireless.h>
 #include <linux/nsproxy.h>
+#include <linux/magic.h>
 
 #include <asm/uaccess.h>
 #include <asm/unistd.h>
@@ -235,8 +236,6 @@ int move_addr_to_user(struct sockaddr *k
 	return __put_user(klen, ulen);
 }
 
-#define SOCKFS_MAGIC 0x534F434B
-
 static struct kmem_cache *sock_inode_cachep __read_mostly;
 
 static struct inode *sock_alloc_inode(struct super_block *sb)

Binary files linux-2.6.31-rc1-pristine/scripts/basic/hash and linux-2.6.31-rc1/scripts/basic/hash differ

security/smack/smack_lsm.c +1 -7
diff -uprN -X linux-2.6.31-rc1-pristine/Documentation/dontdiff linux-2.6.31-rc1-pristine/security/smack/smack_lsm.c linux-2.6.31-rc1/security/smack/smack_lsm.c
@@ -30,17 +30,11 @@
 #include <net/netlabel.h>
 #include <net/cipso_ipv4.h>
 #include <linux/audit.h>
+#include <linux/magic.h>
 #include "smack.h"
 
 #define task_security(task)	(task_cred_xxx((task), security))
 
-/*
- * I hope these are the hokeyist lines of code in the module. Casey.
- */
-#define DEVPTS_SUPER_MAGIC	0x1cd1
-#define SOCKFS_MAGIC		0x534F434B
-#define TMPFS_MAGIC		0x01021994
-
 /**
  * smk_fetch - Fetch the smack label from a file.
  * @ip: a pointer to the inode
Signature · 4 lines
                                      Nick Black <[email protected]>
                                             Principal Engineer, McAfee
                                  Grad student, GT College of Computing
                    "np: the class of dashed hopes, and idle dreams..."
author
#4 lore raw
In reply to nick black

nick black left as an exercise for the reader:

Quoted 10 lines

Pekka Enberg left as an exercise for the reader:

Quoted 5 lines

Hi Nick,
This looks good to me as well but it should be a separate patch as the change has nothing to do with hugetlbfs. While at it, you should probably move SOCKFS_MAGIC and DEVPTS_SUPER_MAGIC to <linux/magic.h> and remove the definitions from smack.

Thanks for the review, Pekka, and I couldn't agree more. Here's a second version of the patch, a rather more equal-opportunity unification of magic numbers (I'll resend with a new Subject if that's preferred):

Ahh, I realize you want two patches. Here's the minimal hugetlbfs patch; I'll send the magic number unification as another thread. My worry there is whether SOCKFS_MAGIC and DEVPTS_SUPER_MAGIC ought be exposed to userspace -- [f]statfs(2)'s manpage makes it clear that HUGETLBFS_MAGIC is to be visible.

[f]statfs(2) *does* refer to DEVFS_SUPER_MAGIC, which doesn't exist anywhere in the 2.6.31-rc1 tree. A typo, or legacy cruft from the devfs of yesteryear? Either way, that doesn't answer whether SOCKFS_ ought be exported.

Thanks very much for the feedback!

fs/hugetlbfs/inode.c +1 -3
diff -uprN -X linux-2.6.31-rc1-pristine/Documentation/dontdiff linux-2.6.31-rc1-pristine/fs/hugetlbfs/inode.c linux-2.6.31-rc1/fs/hugetlbfs/inode.c
@@ -31,12 +31,10 @@
 #include <linux/statfs.h>
 #include <linux/security.h>
 #include <linux/ima.h>
+#include <linux/magic.h>
 
 #include <asm/uaccess.h>
 
-/* some random number */
-#define HUGETLBFS_MAGIC	0x958458f6
-
 static const struct super_operations hugetlbfs_ops;
 static const struct address_space_operations hugetlbfs_aops;
 const struct file_operations hugetlbfs_file_operations;
include/linux/magic.h +1 -0
diff -uprN -X linux-2.6.31-rc1-pristine/Documentation/dontdiff linux-2.6.31-rc1-pristine/include/linux/magic.h linux-2.6.31-rc1/include/linux/magic.h
@@ -13,6 +13,7 @@
 #define SECURITYFS_MAGIC	0x73636673
 #define SELINUX_MAGIC		0xf97cff8c
 #define TMPFS_MAGIC		0x01021994
+#define HUGETLBFS_MAGIC 	0x958458f6	/* some random number */
 #define SQUASHFS_MAGIC		0x73717368
 #define EFS_SUPER_MAGIC		0x414A53
 #define EXT2_SUPER_MAGIC	0xEF53
Signature · 4 lines
                                      Nick Black <[email protected]>
                                             Principal Engineer, McAfee
                                  Grad student, GT College of Computing
                    "np: the class of dashed hopes, and idle dreams..."