Skip to contentSkip to conversation

linux-user: exclude SO_TIMESTAMP cmsg_type from unsuppoted ancillary data

PATCH Superseded Jing Huang 2 participants 4 messages Jul 16, 2012 – Jul 19, 2012

v2 of 6 Superseded Latest is v6 →

lore
Share & tools
lore

Jing Huang

author
#0 lore raw

PATCH v2 3/3 linux-user: exclude SO_TIMESTAMP cmsg_type from unsuppoted ancillary data

This patch excludes SO_TIMESTAMP cmsg_type from unsuppoted ancillary data.

---
 linux-user/syscall.c |    4 +++-
 1 files changed, 3 insertions(+), 1 deletions(-)
linux-user/syscall.c +3 -1
index fc8690d..9fce57c 100644
@@ -1349,7 +1349,9 @@ static inline abi_long host_to_target_cmsg(struct target_msghdr *target_msgh,
         target_cmsg->cmsg_type = tswap32(cmsg->cmsg_type);
         target_cmsg->cmsg_len = tswapal(TARGET_CMSG_LEN(len));
 
-        if (cmsg->cmsg_level != TARGET_SOL_SOCKET || cmsg->cmsg_type != SCM_RIGHTS) {
+        if (cmsg->cmsg_level != TARGET_SOL_SOCKET ||
+                    (cmsg->cmsg_type != SCM_RIGHTS &&
+                                    cmsg->cmsg_type != SO_TIMESTAMP)) {
             gemu_log("Unsupported ancillary data: %d/%d\n", cmsg->cmsg_level, cmsg->cmsg_type);
             memcpy(target_data, data, len);
         } else {
Signature · 1 line
1.7.8.6
#1 lore raw
Quoted 1 line · Jing Huang

This patch excludes SO_TIMESTAMP cmsg_type from unsuppoted ancillary data.

"unsupported".

Quoted 11 lines
---
 linux-user/syscall.c |    4 +++-
 1 files changed, 3 insertions(+), 1 deletions(-)
linux-user/syscall.c +0 -0
index fc8690d..9fce57c 100644

linux-user/syscall.c static inline abi_long host_to_target_cmsg(struct target_msghdr *target_msgh, · line 1357

Quoted 10 lines
linux-user/syscall.c +3 -1
@@ -1349,7 +1349,9 @@ static inline abi_long host_to_target_cmsg(struct target_msghdr *target_msgh,
         target_cmsg->cmsg_type = tswap32(cmsg->cmsg_type);
         target_cmsg->cmsg_len = tswapal(TARGET_CMSG_LEN(len));
 
-        if (cmsg->cmsg_level != TARGET_SOL_SOCKET || cmsg->cmsg_type != SCM_RIGHTS) {
+        if (cmsg->cmsg_level != TARGET_SOL_SOCKET ||
+                    (cmsg->cmsg_type != SCM_RIGHTS &&
+                                    cmsg->cmsg_type != SO_TIMESTAMP)) {
             gemu_log("Unsupported ancillary data: %d/%d\n", cmsg->cmsg_level, cmsg->cmsg_type);
             memcpy(target_data, data, len);
         } else {

This is kind of ugly -- it causes us to process a SO_TIMESTAMP payload (which is a 'struct timeval') in the same way as an SCM_RIGHTS payload (which is an array of file descriptors). This happens to work because a struct timeval is a pair of 32 bit integers, and so "tswap32() all the words in the data" works, but it looks pretty weird. If you want to do it this way you need at least an explanatory comment and really the variables 'fd', 'target_fd', 'numfds' would need to change to something more generic and less fd-specific.

-- PMM

author
#2 lore raw
Quoted 37 lines · Peter Maydell
Quoted 1 line · Jing Huang

This patch excludes SO_TIMESTAMP cmsg_type from unsuppoted ancillary data.

"unsupported".

Quoted 11 lines
---
 linux-user/syscall.c |    4 +++-
 1 files changed, 3 insertions(+), 1 deletions(-)
linux-user/syscall.c +0 -0
index fc8690d..9fce57c 100644

linux-user/syscall.c static inline abi_long host_to_target_cmsg(struct target_msghdr *target_msgh, · line 1357

Quoted 10 lines
linux-user/syscall.c +3 -1
@@ -1349,7 +1349,9 @@ static inline abi_long host_to_target_cmsg(struct target_msghdr *target_msgh,
         target_cmsg->cmsg_type = tswap32(cmsg->cmsg_type);
         target_cmsg->cmsg_len = tswapal(TARGET_CMSG_LEN(len));
 
-        if (cmsg->cmsg_level != TARGET_SOL_SOCKET || cmsg->cmsg_type != SCM_RIGHTS) {
+        if (cmsg->cmsg_level != TARGET_SOL_SOCKET ||
+                    (cmsg->cmsg_type != SCM_RIGHTS &&
+                                    cmsg->cmsg_type != SO_TIMESTAMP)) {
             gemu_log("Unsupported ancillary data: %d/%d\n", cmsg->cmsg_level, cmsg->cmsg_type);
             memcpy(target_data, data, len);
         } else {

This is kind of ugly -- it causes us to process a SO_TIMESTAMP payload (which is a 'struct timeval') in the same way as an SCM_RIGHTS payload (which is an array of file descriptors). This happens to work because a struct timeval is a pair of 32 bit integers, and so "tswap32() all the words in the data" works, but it looks pretty weird. If you want to do it this way you need at least an explanatory comment and really the variables 'fd', 'target_fd', 'numfds' would need to change to something more generic and less fd-specific.

Quoted 1 line

-- PMM

Hmm.. I give up this patch. It is ugly indeed. Additionally, qemu_log doesn't disturb the normal execution of linux-user and show error message either.

#3 lore raw
Quoted 38 lines · Jing Huang
Quoted 37 lines · Peter Maydell
Quoted 1 line · Jing Huang

This patch excludes SO_TIMESTAMP cmsg_type from unsuppoted ancillary data.

"unsupported".

Quoted 11 lines
---
 linux-user/syscall.c |    4 +++-
 1 files changed, 3 insertions(+), 1 deletions(-)
linux-user/syscall.c +0 -0
index fc8690d..9fce57c 100644

linux-user/syscall.c static inline abi_long host_to_target_cmsg(struct target_msghdr *target_msgh, · line 1357

Quoted 10 lines
linux-user/syscall.c +3 -1
@@ -1349,7 +1349,9 @@ static inline abi_long host_to_target_cmsg(struct target_msghdr *target_msgh,
         target_cmsg->cmsg_type = tswap32(cmsg->cmsg_type);
         target_cmsg->cmsg_len = tswapal(TARGET_CMSG_LEN(len));
 
-        if (cmsg->cmsg_level != TARGET_SOL_SOCKET || cmsg->cmsg_type != SCM_RIGHTS) {
+        if (cmsg->cmsg_level != TARGET_SOL_SOCKET ||
+                    (cmsg->cmsg_type != SCM_RIGHTS &&
+                                    cmsg->cmsg_type != SO_TIMESTAMP)) {
             gemu_log("Unsupported ancillary data: %d/%d\n", cmsg->cmsg_level, cmsg->cmsg_type);
             memcpy(target_data, data, len);
         } else {

This is kind of ugly -- it causes us to process a SO_TIMESTAMP payload (which is a 'struct timeval') in the same way as an SCM_RIGHTS payload (which is an array of file descriptors). This happens to work because a struct timeval is a pair of 32 bit integers, and so "tswap32() all the words in the data" works, but it looks pretty weird. If you want to do it this way you need at least an explanatory comment and really the variables 'fd', 'target_fd', 'numfds' would need to change to something more generic and less fd-specific.

Quoted 6 lines
Quoted 1 line

-- PMM

Hmm.. I give up this patch. It is ugly indeed. Additionally, qemu_log doesn't disturb the normal execution of linux-user and show error message either.

I think it's salvageable. As I say, you can either genericise the "copy a pile of 32 bit values" code, or just have another clause to the if() specifically for handling struct timeval payload data.

-- PMM