Skip to contentSkip to conversation

linux-user/syscall.c: Let lv always match val in do_getsockopt()

PATCH In review [email protected] 2 participants 7 messages Jan 14, 2016

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 linux-user/syscall.c: Let lv always match val in do_getsockopt()

From: Chen Gang <[email protected]>

After host_to_target_sock_type(), the length of val may be changed, so calculate the related lv, too.

---
 linux-user/syscall.c | 1 +
 1 file changed, 1 insertion(+)
linux-user/syscall.c +1 -0
index fcdca2a..0e95f35 100644
@@ -1841,6 +1841,7 @@ static abi_long do_getsockopt(int sockfd, int level, int optname,
             return ret;
         if (optname == SO_TYPE) {
             val = host_to_target_sock_type(val);
+            lv = (val >> 8) ? 4 : 1;
         }
         if (len > lv)
             len = lv;
Signature · 1 line
1.9.1
#1 lore raw
Quoted 15 lines · Le 14/01/2016 07:24, [email protected] a écrit :

From: Chen Gang <[email protected]>

After host_to_target_sock_type(), the length of val may be changed, so calculate the related lv, too.

---
 linux-user/syscall.c | 1 +
 1 file changed, 1 insertion(+)
linux-user/syscall.c +0 -0
index fcdca2a..0e95f35 100644

linux-user/syscall.c static abi_long do_getsockopt(int sockfd, int level, int optname, · line 1844

Quoted 4 lines
linux-user/syscall.c +1 -0
@@ -1841,6 +1841,7 @@ static abi_long do_getsockopt(int sockfd, int level, int optname,
             return ret;
         if (optname == SO_TYPE) {
             val = host_to_target_sock_type(val);
+            lv = (val >> 8) ? 4 : 1;

It seems the kernel always returns sizeof(int) (for all archs), what is the aim of reducing the size ?

Quoted 4 lines
linux-user/syscall.c +0 -0
         }
         if (len > lv)
             len = lv;
author
#2 lore raw
Quoted 11 lines · Laurent Vivier
Quoted 10 lines · Le 14/01/2016 07:24, [email protected] a écrit :

From: Chen Gang <[email protected]>

After host_to_target_sock_type(), the length of val may be changed, so calculate the related lv, too.

---
 linux-user/syscall.c | 1 +
 1 file changed, 1 insertion(+)
Quoted 13 lines

linux-user/syscall.c static abi_long do_getsockopt(int sockfd, int level, int optname, · line 1844

Quoted 9 lines
linux-user/syscall.c +1 -0
index fcdca2a..0e95f35 100644
@@ -1841,6 +1841,7 @@ static abi_long do_getsockopt(int sockfd, int level, int optname,
             return ret;
         if (optname == SO_TYPE) {
             val = host_to_target_sock_type(val);
+            lv = (val >> 8) ? 4 : 1;

It seems the kernel always returns sizeof(int) (for all archs), what is the aim of reducing the size ?

I am not quite sure whether kernel always returns sizeof(int) (I guess, it should be).

For me, if you are sure, we can skip this patch.

Thanks.

Signature · 3 lines
Chen Gang (陈刚)

Open, share, and attitude like air, water, and life which God blessed
#3 lore raw
Quoted 26 lines · Chen Gang
Quoted 11 lines · Laurent Vivier
Quoted 10 lines · Le 14/01/2016 07:24, [email protected] a écrit :

From: Chen Gang <[email protected]>

After host_to_target_sock_type(), the length of val may be changed, so calculate the related lv, too.

---
 linux-user/syscall.c | 1 +
 1 file changed, 1 insertion(+)
Quoted 13 lines

linux-user/syscall.c static abi_long do_getsockopt(int sockfd, int level, int optname, · line 1844

Quoted 9 lines
linux-user/syscall.c +1 -0
index fcdca2a..0e95f35 100644
@@ -1841,6 +1841,7 @@ static abi_long do_getsockopt(int sockfd, int level, int optname,
             return ret;
         if (optname == SO_TYPE) {
             val = host_to_target_sock_type(val);
+            lv = (val >> 8) ? 4 : 1;

It seems the kernel always returns sizeof(int) (for all archs), what is the aim of reducing the size ?

Quoted 2 lines

I am not quite sure whether kernel always returns sizeof(int) (I guess, it should be).

it can be 1 only if len is 1, but this is managed below.

Quoted 1 line

For me, if you are sure, we can skip this patch.

Does it fix something ?

Laurent

author
#4 lore raw
Quoted 8 lines · Laurent Vivier
Quoted 3 lines · Chen Gang

I am not quite sure whether kernel always returns sizeof(int) (I guess, it should be).

it can be 1 only if len is 1, but this is managed below.

Excuse me, I do not quite understand your meaning.

For me, if we are sure lv is always 4 for SO_TYPE, we don't need this patch.

If lv may be 1 for SO_TYPE (it means val >> 8 may be zero), after call host_to_target_sock_type, val >> 8 may be non-zero, theoretically. In this case, we need modify lv to 4.

Quoted 4 lines
Quoted 1 line

For me, if you are sure, we can skip this patch.

Does it fix something ?

It is only theoretical, not real world, at present.

Thanks.

Signature · 3 lines
Chen Gang (陈刚)

Open, share, and attitude like air, water, and life which God blessed
#5 lore raw
Quoted 20 lines · Chen Gang
Quoted 8 lines · Laurent Vivier
Quoted 3 lines · Chen Gang

I am not quite sure whether kernel always returns sizeof(int) (I guess, it should be).

it can be 1 only if len is 1, but this is managed below.

Excuse me, I do not quite understand your meaning.

For me, if we are sure lv is always 4 for SO_TYPE, we don't need this patch.

If lv may be 1 for SO_TYPE (it means val >> 8 may be zero), after call host_to_target_sock_type, val >> 8 may be non-zero, theoretically. In this case, we need modify lv to 4.

Quoted 6 lines
Quoted 4 lines
Quoted 1 line

For me, if you are sure, we can skip this patch.

Does it fix something ?

It is only theoretical, not real world, at present.

So I think we can skip it.

Laurent

author
#6 lore raw
Quoted 22 lines · Laurent Vivier
Quoted 20 lines · Chen Gang
Quoted 8 lines · Laurent Vivier
Quoted 3 lines · Chen Gang

I am not quite sure whether kernel always returns sizeof(int) (I guess, it should be).

it can be 1 only if len is 1, but this is managed below.

Excuse me, I do not quite understand your meaning.

For me, if we are sure lv is always 4 for SO_TYPE, we don't need this patch.

If lv may be 1 for SO_TYPE (it means val >> 8 may be zero), after call host_to_target_sock_type, val >> 8 may be non-zero, theoretically. In this case, we need modify lv to 4.

Quoted 9 lines
Quoted 6 lines
Quoted 4 lines
Quoted 1 line

For me, if you are sure, we can skip this patch.

Does it fix something ?

It is only theoretical, not real world, at present.

So I think we can skip it.

It is OK to me.

Thanks.

Signature · 3 lines
Chen Gang (陈刚)

Open, share, and attitude like air, water, and life which God blessed