[Devel] [PATCH RHEL7 COMMIT] ms/x86: Fix norandmaps/ADDR_NO_RANDOMIZE

2017-09-01 Thread Konstantin Khorenko
The commit is pushed to "branch-rh7-3.10.0-693.1.1.vz7.37.x-ovz" and will 
appear at https://src.openvz.org/scm/ovz/vzkernel.git
after rh7-3.10.0-693.1.1.vz7.37.2
-->
commit e11ef19abac817dfce2d7fd1609d9a782e0208f5
Author: Oleg Nesterov 
Date:   Tue Aug 15 17:39:52 2017 +0200

ms/x86: Fix norandmaps/ADDR_NO_RANDOMIZE

Documentation/admin-guide/kernel-parameters.txt says:

norandmaps  Don't use address space randomization. Equivalent
to echo 0 > /proc/sys/kernel/randomize_va_space

but it doesn't work because arch_rnd() which is used to randomize
mm->mmap_base returns a random value unconditionally. And as Kirill
pointed out, ADDR_NO_RANDOMIZE is broken by the same reason.

Just shift the PF_RANDOMIZE check from arch_mmap_rnd() to arch_rnd().

Fixes: 1b028f784e8c ("x86/mm: Introduce mmap_compat_base() for 32-bit 
mmap()")
Signed-off-by: Oleg Nesterov 
Signed-off-by: Thomas Gleixner 
Acked-by: Kirill A. Shutemov 
Acked-by: Cyrill Gorcunov 
Reviewed-by: Dmitry Safonov 
Cc: sta...@vger.kernel.org
Cc: Andy Lutomirski 
Cc: Andrew Morton 
Cc: Borislav Petkov 
Cc: Linus Torvalds 
Link: http://lkml.kernel.org/r/20170815153952.ga1...@redhat.com

(cherry picked from commit 47ac5484fd961420e5ec0bb5b972fde381f57365)
Signed-off-by: Konstantin Khorenko 

Conflicts:
arch/x86/mm/mmap.c
---
 arch/x86/mm/mmap.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/x86/mm/mmap.c b/arch/x86/mm/mmap.c
index a1656c8..22026df 100644
--- a/arch/x86/mm/mmap.c
+++ b/arch/x86/mm/mmap.c
@@ -81,14 +81,14 @@ static int mmap_is_legacy(void)
 
 static unsigned long arch_rnd(unsigned int rndbits)
 {
+   if (!(current->flags & PF_RANDOMIZE))
+   return 0;
return ((unsigned long)get_random_int() &
((1UL << rndbits) - 1)) << PAGE_SHIFT;
 }
 
 unsigned long arch_mmap_rnd(void)
 {
-   if (!(current->flags & PF_RANDOMIZE))
-   return 0;
return arch_rnd(mmap_is_ia32() ? mmap32_rnd_bits : mmap64_rnd_bits);
 }
 
___
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel


[Devel] [PATCH RHEL7 COMMIT] ms/x86: Fix norandmaps/ADDR_NO_RANDOMIZE

2017-09-01 Thread Konstantin Khorenko
The commit is pushed to "branch-rh7-3.10.0-514.26.1.vz7.35.x-ovz" and will 
appear at https://src.openvz.org/scm/ovz/vzkernel.git
after rh7-3.10.0-514.26.1.vz7.35.6
-->
commit 4fa8137c41058394c9935c2d18a22c8983a948c6
Author: Oleg Nesterov 
Date:   Tue Aug 15 17:39:52 2017 +0200

ms/x86: Fix norandmaps/ADDR_NO_RANDOMIZE

Documentation/admin-guide/kernel-parameters.txt says:

norandmaps  Don't use address space randomization. Equivalent
to echo 0 > /proc/sys/kernel/randomize_va_space

but it doesn't work because arch_rnd() which is used to randomize
mm->mmap_base returns a random value unconditionally. And as Kirill
pointed out, ADDR_NO_RANDOMIZE is broken by the same reason.

Just shift the PF_RANDOMIZE check from arch_mmap_rnd() to arch_rnd().

Fixes: 1b028f784e8c ("x86/mm: Introduce mmap_compat_base() for 32-bit 
mmap()")
Signed-off-by: Oleg Nesterov 
Signed-off-by: Thomas Gleixner 
Acked-by: Kirill A. Shutemov 
Acked-by: Cyrill Gorcunov 
Reviewed-by: Dmitry Safonov 
Cc: sta...@vger.kernel.org
Cc: Andy Lutomirski 
Cc: Andrew Morton 
Cc: Borislav Petkov 
Cc: Linus Torvalds 
Link: http://lkml.kernel.org/r/20170815153952.ga1...@redhat.com

(cherry picked from commit 47ac5484fd961420e5ec0bb5b972fde381f57365)
Signed-off-by: Konstantin Khorenko 

Conflicts:
arch/x86/mm/mmap.c
---
 arch/x86/mm/mmap.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/x86/mm/mmap.c b/arch/x86/mm/mmap.c
index a1656c8..22026df 100644
--- a/arch/x86/mm/mmap.c
+++ b/arch/x86/mm/mmap.c
@@ -81,14 +81,14 @@ static int mmap_is_legacy(void)
 
 static unsigned long arch_rnd(unsigned int rndbits)
 {
+   if (!(current->flags & PF_RANDOMIZE))
+   return 0;
return ((unsigned long)get_random_int() &
((1UL << rndbits) - 1)) << PAGE_SHIFT;
 }
 
 unsigned long arch_mmap_rnd(void)
 {
-   if (!(current->flags & PF_RANDOMIZE))
-   return 0;
return arch_rnd(mmap_is_ia32() ? mmap32_rnd_bits : mmap64_rnd_bits);
 }
 
___
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel


Re: [Devel] [RFC PATCH 2/2] autofs: sent 32-bit sized packet for 32-bit process

2017-09-01 Thread Stanislav Kinsburskiy


31.08.2017 20:22, Dmitry V. Levin пишет:
> On Thu, Aug 31, 2017 at 05:57:11PM +0400, Stanislav Kinsburskiy wrote:
>> The structure autofs_v5_packet (except name) is not aligned by 8 bytes, which
>> lead to different sizes in 32 and 64-bit architectures.
>> Let's form 32-bit compatible packet when daemon has 32-bit addressation.
>>
>> Signed-off-by: Stanislav Kinsburskiy 
>> ---
>>  fs/autofs4/waitq.c |   11 +--
>>  1 file changed, 9 insertions(+), 2 deletions(-)
>>
>> diff --git a/fs/autofs4/waitq.c b/fs/autofs4/waitq.c
>> index 309ca6b..484cf2e 100644
>> --- a/fs/autofs4/waitq.c
>> +++ b/fs/autofs4/waitq.c
>> @@ -153,12 +153,19 @@ static void autofs4_notify_daemon(struct 
>> autofs_sb_info *sbi,
>>  {
>>  struct autofs_v5_packet *packet = &pkt.v5_pkt.v5_packet;
>>  struct user_namespace *user_ns = sbi->pipe->f_cred->user_ns;
>> +size_t name_offset;
>>  
>> -pktsz = sizeof(*packet);
>> +if (sbi->is32bit)
>> +name_offset = offsetof(struct autofs_v5_packet, len) +
>> +  sizeof(packet->len);
>> +else
>> +name_offset = offsetof(struct autofs_v5_packet, name);
> 
> This doesn't help at all because the offset of struct autofs_v5_packet.name
> does not change.
> 
>> +pktsz = name_offset + sizeof(packet->name);
> 
> What changes is pktsz: it's either sizeof(struct autofs_v5_packet)
> or 4 bytes less, depending on the architecture.

Indeed. Thanks!

> For example,
> 
> #ifdef CONFIG_COMPAT
>   if (__alignof__(compat_u64) < __alignof__(u64) && sbi->is32bit)

Unfortunately I don't get this "alignof" checks.
The intention of "is32bit" was to define this compat case completely.
Why are they required?

>   pktsz = offsetofend(struct autofs_v5_packet, name);
>   else
> #endif
>   pktsz = sizeof(*packet);
> 
> 



___
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel


[Devel] [PATCH] autofs: fix double pid put in error path

2017-09-01 Thread Stanislav Kinsburskiy
Signed-off-by: Stanislav Kinsburskiy 
---
 fs/autofs4/inode.c |1 -
 1 file changed, 1 deletion(-)

diff --git a/fs/autofs4/inode.c b/fs/autofs4/inode.c
index b23cf2a..0ba9c02 100644
--- a/fs/autofs4/inode.c
+++ b/fs/autofs4/inode.c
@@ -343,7 +343,6 @@ int autofs4_fill_super(struct super_block *s, void *data, 
int silent)
 fail_ino:
kfree(ino);
 fail_free:
-   put_pid(sbi->oz_pgrp);
kfree(sbi);
s->s_fs_info = NULL;
return ret;

___
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel


[Devel] [PATCH] autofs: fix leaked pid on error path in autofs4_fill_super

2017-09-01 Thread Stanislav Kinsburskiy
Check for protocol happens after pid get.

Signed-off-by: Stanislav Kinsburskiy 
---
 fs/autofs4/inode.c |2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/fs/autofs4/inode.c b/fs/autofs4/inode.c
index 0ba9c02..2cd4e7e 100644
--- a/fs/autofs4/inode.c
+++ b/fs/autofs4/inode.c
@@ -298,7 +298,7 @@ int autofs4_fill_super(struct super_block *s, void *data, 
int silent)
   "daemon (%d, %d) kernel (%d, %d)\n",
sbi->min_proto, sbi->max_proto,
AUTOFS_MIN_PROTO_VERSION, AUTOFS_MAX_PROTO_VERSION);
-   goto fail_dput;
+   goto fail_put_pid;
}
 
/* Establish highest kernel protocol version */

___
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel


[Devel] [RFC PATCH 1/2] autofs: set compat flag on sbi when daemon uses 32bit addressation

2017-09-01 Thread Stanislav Kinsburskiy
Signed-off-by: Stanislav Kinsburskiy 
---
 fs/autofs4/autofs_i.h  |3 +++
 fs/autofs4/dev-ioctl.c |3 +++
 fs/autofs4/inode.c |4 +++-
 3 files changed, 9 insertions(+), 1 deletion(-)

diff --git a/fs/autofs4/autofs_i.h b/fs/autofs4/autofs_i.h
index 4737615..3da105f 100644
--- a/fs/autofs4/autofs_i.h
+++ b/fs/autofs4/autofs_i.h
@@ -120,6 +120,9 @@ struct autofs_sb_info {
struct list_head active_list;
struct list_head expiring_list;
struct rcu_head rcu;
+#ifdef CONFIG_COMPAT
+   unsigned is32bit:1;
+#endif
 };
 
 static inline struct autofs_sb_info *autofs4_sbi(struct super_block *sb)
diff --git a/fs/autofs4/dev-ioctl.c b/fs/autofs4/dev-ioctl.c
index b7c816f..467d6c4 100644
--- a/fs/autofs4/dev-ioctl.c
+++ b/fs/autofs4/dev-ioctl.c
@@ -397,6 +397,9 @@ static int autofs_dev_ioctl_setpipefd(struct file *fp,
sbi->pipefd = pipefd;
sbi->pipe = pipe;
sbi->catatonic = 0;
+#ifdef CONFIG_COMPAT
+   sbi->is32bit = is_compat_task();
+#endif
}
 out:
put_pid(new_pid);
diff --git a/fs/autofs4/inode.c b/fs/autofs4/inode.c
index 09e7d68..21d3c0b 100644
--- a/fs/autofs4/inode.c
+++ b/fs/autofs4/inode.c
@@ -301,7 +301,9 @@ int autofs4_fill_super(struct super_block *s, void *data, 
int silent)
} else {
sbi->oz_pgrp = get_task_pid(current, PIDTYPE_PGID);
}
-
+#ifdef CONFIG_COMPAT
+   sbi->is32bit = is_compat_task();
+#endif
if (autofs_type_trigger(sbi->type))
__managed_dentry_set_managed(root);
 

___
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel


[Devel] [RFC PATCH 0/2] autofs: fix autofs_v5_packet dlivery in compat mode

2017-09-01 Thread Stanislav Kinsburskiy
The problem is that in compat mode struct autofs_v5_packet has to have 
different size
(i.e. 4 bytes less).

This is RFC because:
1) This issue is hidden, because autofs pipe has O_DIRECT and the rest of the
epacket is truncated when read.
2) X86 arch doesn't have is_compat_task() helper
3) It's now clear, what to do if "pgrp" option is specified.

The following series implements...

---

Stanislav Kinsburskiy (2):
  autofs: set compat flag on sbi when daemon uses 32bit addressation
  autofs: sent 32-bit sized packet for 32-bit process


 fs/autofs4/autofs_i.h  |3 +++
 fs/autofs4/dev-ioctl.c |3 +++
 fs/autofs4/inode.c |4 +++-
 fs/autofs4/waitq.c |5 +
 4 files changed, 14 insertions(+), 1 deletion(-)
___
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel


[Devel] [RFC PATCH 2/2] autofs: sent 32-bit sized packet for 32-bit process

2017-09-01 Thread Stanislav Kinsburskiy
The structure autofs_v5_packet (except name) is not aligned by 8 bytes, which
leads to different sizes in 32 and 64-bit architectures.
Let's form 32-bit compatible packet when daemon has 32-bit addressation.

Suggested-by: Dmitry V. Levin 
Signed-off-by: Stanislav Kinsburskiy 
---
 fs/autofs4/waitq.c |5 +
 1 file changed, 5 insertions(+)

diff --git a/fs/autofs4/waitq.c b/fs/autofs4/waitq.c
index 24a58bf..1f9b7d8 100644
--- a/fs/autofs4/waitq.c
+++ b/fs/autofs4/waitq.c
@@ -151,6 +151,11 @@ static void autofs4_notify_daemon(struct autofs_sb_info 
*sbi,
struct autofs_v5_packet *packet = &pkt.v5_pkt.v5_packet;
struct user_namespace *user_ns = sbi->pipe->f_cred->user_ns;
 
+#ifdef CONFIG_COMPAT
+   if (sbi->is32bit)
+   pktsz = offsetofend(struct autofs_v5_packet, name);
+   else
+#endif
pktsz = sizeof(*packet);
 
packet->wait_queue_token = wq->wait_queue_token;

___
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel


[Devel] [PATCH] tests: do not try to read more than packet in AutoFS test

2017-09-01 Thread Stanislav Kinsburskiy
The intention was to make sure, that only one packet is sent at a time.
And thus read has to return exactly the size of one packet.
But it doesnt' work as expected, because size of autofs_v5_packet_union
differs on 32 bit and 64 bit architectures.
This is a bug, but it's hidden so deeply, that no one really cares by the
following 2 aspects:
1) Autofs pipe has O_DIRECT flag, which means excess bytes will be discarded
upon read.
2) No one tries to read more than one packet at a time.

So let's fix the test instead and do not try to read more bytes, than
expected.

https://jira.sw.ru/browse/PSBM-71078

Signed-off-by: Stanislav Kinsburskiy 
---
 test/zdtm/static/autofs.c |   13 +
 1 file changed, 5 insertions(+), 8 deletions(-)

diff --git a/test/zdtm/static/autofs.c b/test/zdtm/static/autofs.c
index 747ab69..ae78538 100644
--- a/test/zdtm/static/autofs.c
+++ b/test/zdtm/static/autofs.c
@@ -460,7 +460,7 @@ static int automountd_loop(int pipe, const char 
*mountpoint, struct autofs_param
 {
union autofs_v5_packet_union *packet;
ssize_t bytes;
-   size_t psize = sizeof(*packet) + 1;
+   size_t psize = sizeof(*packet);
int err = 0;
 
packet = malloc(psize);
@@ -473,7 +473,7 @@ static int automountd_loop(int pipe, const char 
*mountpoint, struct autofs_param
siginterrupt(SIGUSR2, 1);
 
while (!stop && !err) {
-   memset(packet, 0, sizeof(*packet));
+   memset(packet, 0, psize);
 
bytes = read(pipe, packet, psize);
if (bytes < 0) {
@@ -483,12 +483,9 @@ static int automountd_loop(int pipe, const char 
*mountpoint, struct autofs_param
}
continue;
}
-   if (bytes == psize) {
-   pr_err("read more that expected\n");
-   return -EINVAL;
-   }
-   if (bytes != sizeof(*packet)) {
-   pr_err("read less than expected: %zd\n", bytes);
+   if (bytes != psize) {
+   pr_err("read less than expected: %zd < %zd\n",
+   bytes, psize);
return -EINVAL;
}
err = automountd_serve(mountpoint, param, packet);

___
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel


[Devel] [PATCH] zdtm: fix autofs to work with autofs_v5_packet_union issue

2017-09-01 Thread Stanislav Kinsburskiy
The only patch in the series discards the following CRIU commits:

27ce0613e7319c97cc7bfc0a240e3f5f61f3d912
e90b5ed57af866010bc8f5c7c9730aa68995cb77
2fc59ffe3ead2eff44542a415f16b1559e2c8140

The following series implements...

---

Stanislav Kinsburskiy (1):
  tests: do not try to read more than packet in AutoFS test


 test/zdtm/static/autofs.c |   13 +
 1 file changed, 5 insertions(+), 8 deletions(-)

___
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel


Re: [Devel] [RFC PATCH 2/2] autofs: sent 32-bit sized packet for 32-bit process

2017-09-01 Thread Dmitry V. Levin
On Fri, Sep 01, 2017 at 12:15:17PM +0300, Stanislav Kinsburskiy wrote:
> 31.08.2017 20:22, Dmitry V. Levin пишет:
> > On Thu, Aug 31, 2017 at 05:57:11PM +0400, Stanislav Kinsburskiy wrote:
> >> The structure autofs_v5_packet (except name) is not aligned by 8 bytes, 
> >> which
> >> lead to different sizes in 32 and 64-bit architectures.
> >> Let's form 32-bit compatible packet when daemon has 32-bit addressation.
> >>
> >> Signed-off-by: Stanislav Kinsburskiy 
> >> ---
> >>  fs/autofs4/waitq.c |   11 +--
> >>  1 file changed, 9 insertions(+), 2 deletions(-)
> >>
> >> diff --git a/fs/autofs4/waitq.c b/fs/autofs4/waitq.c
> >> index 309ca6b..484cf2e 100644
> >> --- a/fs/autofs4/waitq.c
> >> +++ b/fs/autofs4/waitq.c
> >> @@ -153,12 +153,19 @@ static void autofs4_notify_daemon(struct 
> >> autofs_sb_info *sbi,
> >>{
> >>struct autofs_v5_packet *packet = &pkt.v5_pkt.v5_packet;
> >>struct user_namespace *user_ns = sbi->pipe->f_cred->user_ns;
> >> +  size_t name_offset;
> >>  
> >> -  pktsz = sizeof(*packet);
> >> +  if (sbi->is32bit)
> >> +  name_offset = offsetof(struct autofs_v5_packet, len) +
> >> +sizeof(packet->len);
> >> +  else
> >> +  name_offset = offsetof(struct autofs_v5_packet, name);
> > 
> > This doesn't help at all because the offset of struct autofs_v5_packet.name
> > does not change.
> > 
> >> +  pktsz = name_offset + sizeof(packet->name);
> > 
> > What changes is pktsz: it's either sizeof(struct autofs_v5_packet)
> > or 4 bytes less, depending on the architecture.
> 
> Indeed. Thanks!
> 
> > For example,
> > 
> > #ifdef CONFIG_COMPAT
> > if (__alignof__(compat_u64) < __alignof__(u64) && sbi->is32bit)
> 
> Unfortunately I don't get this "alignof" checks.
> The intention of "is32bit" was to define this compat case completely.
> Why are they required?

On some 32-bit architectures like arm, u64 is 64-bit aligned, on others
like x86 it is not.  This alignof check ensures that compat 32-bit
architectures with 64-bit alignment are not going to be broken
by the change.


-- 
ldv


signature.asc
Description: PGP signature
___
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel


Re: [Devel] [RFC PATCH 2/2] autofs: sent 32-bit sized packet for 32-bit process

2017-09-01 Thread Stanislav Kinsburskiy


01.09.2017 16:53, Dmitry V. Levin P?P8QP5Q:
> On Fri, Sep 01, 2017 at 12:15:17PM +0300, Stanislav Kinsburskiy wrote:
>> 31.08.2017 20:22, Dmitry V. Levin P?P8QP5Q:
>>> On Thu, Aug 31, 2017 at 05:57:11PM +0400, Stanislav Kinsburskiy wrote:
 The structure autofs_v5_packet (except name) is not aligned by 8 bytes, 
 which
 lead to different sizes in 32 and 64-bit architectures.
 Let's form 32-bit compatible packet when daemon has 32-bit addressation.

 Signed-off-by: Stanislav Kinsburskiy 
 ---
  fs/autofs4/waitq.c |   11 +--
  1 file changed, 9 insertions(+), 2 deletions(-)

 diff --git a/fs/autofs4/waitq.c b/fs/autofs4/waitq.c
 index 309ca6b..484cf2e 100644
 --- a/fs/autofs4/waitq.c
 +++ b/fs/autofs4/waitq.c
 @@ -153,12 +153,19 @@ static void autofs4_notify_daemon(struct 
 autofs_sb_info *sbi,
{
struct autofs_v5_packet *packet = &pkt.v5_pkt.v5_packet;
struct user_namespace *user_ns = sbi->pipe->f_cred->user_ns;
 +  size_t name_offset;
  
 -  pktsz = sizeof(*packet);
 +  if (sbi->is32bit)
 +  name_offset = offsetof(struct autofs_v5_packet, len) +
 +sizeof(packet->len);
 +  else
 +  name_offset = offsetof(struct autofs_v5_packet, name);
>>>
>>> This doesn't help at all because the offset of struct autofs_v5_packet.name
>>> does not change.
>>>
 +  pktsz = name_offset + sizeof(packet->name);
>>>
>>> What changes is pktsz: it's either sizeof(struct autofs_v5_packet)
>>> or 4 bytes less, depending on the architecture.
>>
>> Indeed. Thanks!
>>
>>> For example,
>>>
>>> #ifdef CONFIG_COMPAT
>>> if (__alignof__(compat_u64) < __alignof__(u64) && sbi->is32bit)
>>
>> Unfortunately I don't get this "alignof" checks.
>> The intention of "is32bit" was to define this compat case completely.
>> Why are they required?
> 
> On some 32-bit architectures like arm, u64 is 64-bit aligned, on others
> like x86 it is not.  This alignof check ensures that compat 32-bit
> architectures with 64-bit alignment are not going to be broken
> by the change.
> 

Thanks for the explanation!
But looks like the issue is hidden so deep (thanks to O_DIRECT), that becomes 
unimportant.

> 
> 
> 
> ___
> Devel mailing list
> Devel@openvz.org
> https://lists.openvz.org/mailman/listinfo/devel
> 
___
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel


Re: [Devel] [RFC PATCH 2/2] autofs: sent 32-bit sized packet for 32-bit process

2017-09-01 Thread Dmitry V. Levin
On Fri, Sep 01, 2017 at 05:02:45PM +0300, Stanislav Kinsburskiy wrote:
> 
> 
> 01.09.2017 16:53, Dmitry V. Levin P?P8QP5Q:
> > On Fri, Sep 01, 2017 at 12:15:17PM +0300, Stanislav Kinsburskiy wrote:
> >> 31.08.2017 20:22, Dmitry V. Levin P?P8QP5Q:
> >>> On Thu, Aug 31, 2017 at 05:57:11PM +0400, Stanislav Kinsburskiy wrote:
>  The structure autofs_v5_packet (except name) is not aligned by 8 bytes, 
>  which
>  lead to different sizes in 32 and 64-bit architectures.
>  Let's form 32-bit compatible packet when daemon has 32-bit addressation.
> 
>  Signed-off-by: Stanislav Kinsburskiy 
>  ---
>   fs/autofs4/waitq.c |   11 +--
>   1 file changed, 9 insertions(+), 2 deletions(-)
> 
>  diff --git a/fs/autofs4/waitq.c b/fs/autofs4/waitq.c
>  index 309ca6b..484cf2e 100644
>  --- a/fs/autofs4/waitq.c
>  +++ b/fs/autofs4/waitq.c
>  @@ -153,12 +153,19 @@ static void autofs4_notify_daemon(struct 
>  autofs_sb_info *sbi,
>   {
>   struct autofs_v5_packet *packet = &pkt.v5_pkt.v5_packet;
>   struct user_namespace *user_ns = 
>  sbi->pipe->f_cred->user_ns;
>  +size_t name_offset;
>   
>  -pktsz = sizeof(*packet);
>  +if (sbi->is32bit)
>  +name_offset = offsetof(struct autofs_v5_packet, 
>  len) +
>  +  sizeof(packet->len);
>  +else
>  +name_offset = offsetof(struct autofs_v5_packet, 
>  name);
> >>>
> >>> This doesn't help at all because the offset of struct 
> >>> autofs_v5_packet.name
> >>> does not change.
> >>>
>  +pktsz = name_offset + sizeof(packet->name);
> >>>
> >>> What changes is pktsz: it's either sizeof(struct autofs_v5_packet)
> >>> or 4 bytes less, depending on the architecture.
> >>
> >> Indeed. Thanks!
> >>
> >>> For example,
> >>>
> >>> #ifdef CONFIG_COMPAT
> >>>   if (__alignof__(compat_u64) < __alignof__(u64) && sbi->is32bit)
> >>
> >> Unfortunately I don't get this "alignof" checks.
> >> The intention of "is32bit" was to define this compat case completely.
> >> Why are they required?
> > 
> > On some 32-bit architectures like arm, u64 is 64-bit aligned, on others
> > like x86 it is not.  This alignof check ensures that compat 32-bit
> > architectures with 64-bit alignment are not going to be broken
> > by the change.
> 
> Thanks for the explanation!
> But looks like the issue is hidden so deep (thanks to O_DIRECT), that becomes 
> unimportant.

I'm not quite sure how O_DIRECT makes this unimportant.
For example, automount_dispatch_io from systemd tries to read exactly
sizeof(union autofs_v5_packet_union) bytes and fails in case of short read.


-- 
ldv


signature.asc
Description: PGP signature
___
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel