linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/2] vfs: make sure struct filename->iname is word-aligned
@ 2016-02-16 22:49 Rasmus Villemoes
  2016-02-16 22:49 ` [PATCH 2/2] vfs: don't always include audit-specific members of struct filename Rasmus Villemoes
  2016-02-16 22:57 ` [PATCH 1/2] vfs: make sure struct filename->iname is word-aligned Al Viro
  0 siblings, 2 replies; 6+ messages in thread
From: Rasmus Villemoes @ 2016-02-16 22:49 UTC (permalink / raw)
  To: Alexander Viro, Jeff Layton, J. Bruce Fields
  Cc: Rasmus Villemoes, Linus Torvalds, linux-fsdevel, linux-kernel

I noticed that offsetof(struct filename, iname) is actually 28 on 64
bit platforms, so we always pass an unaligned pointer to
strncpy_from_user. This is mostly a problem for those 64 bit platforms
without HAVE_EFFICIENT_UNALIGNED_ACCESS, but even on x86_64, unaligned
accesses carry a penalty, especially when done in a loop.

Let's try to ensure we always pass an aligned destination pointer to
strncpy_from_user. I considered making refcnt a long instead of doing
the union thing, and mostly ended up tossing a coin.

Signed-off-by: Rasmus Villemoes <linux@rasmusvillemoes.dk>
---
Cc'ing Linus, not because it's urgent in any way, but because he's
usually interested in strncpy_from_user and he can probably tell me
why this is completely immaterial.

 fs/namei.c         | 2 ++
 include/linux/fs.h | 5 ++++-
 2 files changed, 6 insertions(+), 1 deletion(-)

diff --git a/fs/namei.c b/fs/namei.c
index f624d132e01e..bd150fa799a2 100644
--- a/fs/namei.c
+++ b/fs/namei.c
@@ -35,6 +35,7 @@
 #include <linux/fs_struct.h>
 #include <linux/posix_acl.h>
 #include <linux/hash.h>
+#include <linux/bug.h>
 #include <asm/uaccess.h>
 
 #include "internal.h"
@@ -127,6 +128,7 @@ getname_flags(const char __user *filename, int flags, int *empty)
 	struct filename *result;
 	char *kname;
 	int len;
+	BUILD_BUG_ON(offsetof(struct filename, iname) % sizeof(long) != 0);
 
 	result = audit_reusename(filename);
 	if (result)
diff --git a/include/linux/fs.h b/include/linux/fs.h
index ae681002100a..d522e6391855 100644
--- a/include/linux/fs.h
+++ b/include/linux/fs.h
@@ -2245,7 +2245,10 @@ struct filename {
 	const char		*name;	/* pointer to actual string */
 	const __user char	*uptr;	/* original userland pointer */
 	struct audit_names	*aname;
-	int			refcnt;
+	union {
+		int		refcnt;
+		long		__padding;
+	};
 	const char		iname[];
 };
 
-- 
2.1.4


^ permalink raw reply related	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2016-02-22 23:59 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-02-16 22:49 [PATCH 1/2] vfs: make sure struct filename->iname is word-aligned Rasmus Villemoes
2016-02-16 22:49 ` [PATCH 2/2] vfs: don't always include audit-specific members of struct filename Rasmus Villemoes
2016-02-16 22:57 ` [PATCH 1/2] vfs: make sure struct filename->iname is word-aligned Al Viro
2016-02-18 20:10   ` Rasmus Villemoes
2016-02-19 15:00     ` Theodore Ts'o
2016-02-22 23:59       ` Rasmus Villemoes

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).