summaryrefslogtreecommitdiffstats
path: root/recipes-kernel/linux/linux-ti33x-psp-3.2/3.2.10/0001-autofs-work-around-unhappy-compat-problem-on-x86-64.patch
diff options
context:
space:
mode:
Diffstat (limited to 'recipes-kernel/linux/linux-ti33x-psp-3.2/3.2.10/0001-autofs-work-around-unhappy-compat-problem-on-x86-64.patch')
-rw-r--r--recipes-kernel/linux/linux-ti33x-psp-3.2/3.2.10/0001-autofs-work-around-unhappy-compat-problem-on-x86-64.patch142
1 files changed, 142 insertions, 0 deletions
diff --git a/recipes-kernel/linux/linux-ti33x-psp-3.2/3.2.10/0001-autofs-work-around-unhappy-compat-problem-on-x86-64.patch b/recipes-kernel/linux/linux-ti33x-psp-3.2/3.2.10/0001-autofs-work-around-unhappy-compat-problem-on-x86-64.patch
new file mode 100644
index 00000000..16804db8
--- /dev/null
+++ b/recipes-kernel/linux/linux-ti33x-psp-3.2/3.2.10/0001-autofs-work-around-unhappy-compat-problem-on-x86-64.patch
@@ -0,0 +1,142 @@
1From 472122b7b0040118eae3846c9bfbb97225f1ab11 Mon Sep 17 00:00:00 2001
2From: Ian Kent <raven@themaw.net>
3Date: Wed, 22 Feb 2012 20:45:44 +0800
4Subject: [PATCH 01/95] autofs: work around unhappy compat problem on x86-64
5
6commit a32744d4abae24572eff7269bc17895c41bd0085 upstream.
7
8When the autofs protocol version 5 packet type was added in commit
95c0a32fc2cd0 ("autofs4: add new packet type for v5 communications"), it
10obvously tried quite hard to be word-size agnostic, and uses explicitly
11sized fields that are all correctly aligned.
12
13However, with the final "char name[NAME_MAX+1]" array at the end, the
14actual size of the structure ends up being not very well defined:
15because the struct isn't marked 'packed', doing a "sizeof()" on it will
16align the size of the struct up to the biggest alignment of the members
17it has.
18
19And despite all the members being the same, the alignment of them is
20different: a "__u64" has 4-byte alignment on x86-32, but native 8-byte
21alignment on x86-64. And while 'NAME_MAX+1' ends up being a nice round
22number (256), the name[] array starts out a 4-byte aligned.
23
24End result: the "packed" size of the structure is 300 bytes: 4-byte, but
25not 8-byte aligned.
26
27As a result, despite all the fields being in the same place on all
28architectures, sizeof() will round up that size to 304 bytes on
29architectures that have 8-byte alignment for u64.
30
31Note that this is *not* a problem for 32-bit compat mode on POWER, since
32there __u64 is 8-byte aligned even in 32-bit mode. But on x86, 32-bit
33and 64-bit alignment is different for 64-bit entities, and as a result
34the structure that has exactly the same layout has different sizes.
35
36So on x86-64, but no other architecture, we will just subtract 4 from
37the size of the structure when running in a compat task. That way we
38will write the properly sized packet that user mode expects.
39
40Not pretty. Sadly, this very subtle, and unnecessary, size difference
41has been encoded in user space that wants to read packets of *exactly*
42the right size, and will refuse to touch anything else.
43
44Reported-and-tested-by: Thomas Meyer <thomas@m3y3r.de>
45Signed-off-by: Ian Kent <raven@themaw.net>
46Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
47Cc: Jonathan Nieder <jrnieder@gmail.com>
48Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
49---
50 fs/autofs4/autofs_i.h | 1 +
51 fs/autofs4/dev-ioctl.c | 1 +
52 fs/autofs4/inode.c | 2 ++
53 fs/autofs4/waitq.c | 22 +++++++++++++++++++---
54 4 files changed, 23 insertions(+), 3 deletions(-)
55
56diff --git a/fs/autofs4/autofs_i.h b/fs/autofs4/autofs_i.h
57index 326dc08..308a98b 100644
58--- a/fs/autofs4/autofs_i.h
59+++ b/fs/autofs4/autofs_i.h
60@@ -110,6 +110,7 @@ struct autofs_sb_info {
61 int sub_version;
62 int min_proto;
63 int max_proto;
64+ int compat_daemon;
65 unsigned long exp_timeout;
66 unsigned int type;
67 int reghost_enabled;
68diff --git a/fs/autofs4/dev-ioctl.c b/fs/autofs4/dev-ioctl.c
69index 509fe1e..56bac70 100644
70--- a/fs/autofs4/dev-ioctl.c
71+++ b/fs/autofs4/dev-ioctl.c
72@@ -385,6 +385,7 @@ static int autofs_dev_ioctl_setpipefd(struct file *fp,
73 sbi->pipefd = pipefd;
74 sbi->pipe = pipe;
75 sbi->catatonic = 0;
76+ sbi->compat_daemon = is_compat_task();
77 }
78 out:
79 mutex_unlock(&sbi->wq_mutex);
80diff --git a/fs/autofs4/inode.c b/fs/autofs4/inode.c
81index 8179f1a..98a5695 100644
82--- a/fs/autofs4/inode.c
83+++ b/fs/autofs4/inode.c
84@@ -19,6 +19,7 @@
85 #include <linux/parser.h>
86 #include <linux/bitops.h>
87 #include <linux/magic.h>
88+#include <linux/compat.h>
89 #include "autofs_i.h"
90 #include <linux/module.h>
91
92@@ -224,6 +225,7 @@ int autofs4_fill_super(struct super_block *s, void *data, int silent)
93 set_autofs_type_indirect(&sbi->type);
94 sbi->min_proto = 0;
95 sbi->max_proto = 0;
96+ sbi->compat_daemon = is_compat_task();
97 mutex_init(&sbi->wq_mutex);
98 spin_lock_init(&sbi->fs_lock);
99 sbi->queues = NULL;
100diff --git a/fs/autofs4/waitq.c b/fs/autofs4/waitq.c
101index e1fbdee..6861f61 100644
102--- a/fs/autofs4/waitq.c
103+++ b/fs/autofs4/waitq.c
104@@ -90,7 +90,24 @@ static int autofs4_write(struct file *file, const void *addr, int bytes)
105
106 return (bytes > 0);
107 }
108-
109+
110+/*
111+ * The autofs_v5 packet was misdesigned.
112+ *
113+ * The packets are identical on x86-32 and x86-64, but have different
114+ * alignment. Which means that 'sizeof()' will give different results.
115+ * Fix it up for the case of running 32-bit user mode on a 64-bit kernel.
116+ */
117+static noinline size_t autofs_v5_packet_size(struct autofs_sb_info *sbi)
118+{
119+ size_t pktsz = sizeof(struct autofs_v5_packet);
120+#if defined(CONFIG_X86_64) && defined(CONFIG_COMPAT)
121+ if (sbi->compat_daemon > 0)
122+ pktsz -= 4;
123+#endif
124+ return pktsz;
125+}
126+
127 static void autofs4_notify_daemon(struct autofs_sb_info *sbi,
128 struct autofs_wait_queue *wq,
129 int type)
130@@ -147,8 +164,7 @@ static void autofs4_notify_daemon(struct autofs_sb_info *sbi,
131 {
132 struct autofs_v5_packet *packet = &pkt.v5_pkt.v5_packet;
133
134- pktsz = sizeof(*packet);
135-
136+ pktsz = autofs_v5_packet_size(sbi);
137 packet->wait_queue_token = wq->wait_queue_token;
138 packet->len = wq->name.len;
139 memcpy(packet->name, wq->name.name, wq->name.len);
140--
1411.7.9.4
142