qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH] linux-user/syscall.c: Let all lock_user_struct() and unlock_user_struct() paired with each other
@ 2015-01-25 12:06 Chen Gang S
  2015-01-25 12:49 ` Peter Maydell
  0 siblings, 1 reply; 12+ messages in thread
From: Chen Gang S @ 2015-01-25 12:06 UTC (permalink / raw)
  To: riku.voipio, Peter Maydell; +Cc: QEMU Trivial, qemu-devel

lock_user_struct() and unlock_user_struct() need always be paired with
each other, or will cause resource leak.

Also remove redundant check for 'target_mb' in abi_long do_msgrcv().

Also match the coding styles found by "./scripts/checkpatch.pl".

Signed-off-by: Chen Gang <gang.chen.5i5j@gmail.com>
---
 linux-user/syscall.c | 27 +++++++++++++++++++--------
 1 file changed, 19 insertions(+), 8 deletions(-)

diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index ec9e4fc..b2da432 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -2518,8 +2518,10 @@ static inline abi_long target_to_host_semid_ds(struct semid_ds *host_sd,
 
     if (!lock_user_struct(VERIFY_READ, target_sd, target_addr, 1))
         return -TARGET_EFAULT;
-    if (target_to_host_ipc_perm(&(host_sd->sem_perm),target_addr))
+    if (target_to_host_ipc_perm(&(host_sd->sem_perm), target_addr)) {
+        unlock_user_struct(target_sd, target_addr, 0);
         return -TARGET_EFAULT;
+    }
     host_sd->sem_nsems = tswapal(target_sd->sem_nsems);
     host_sd->sem_otime = tswapal(target_sd->sem_otime);
     host_sd->sem_ctime = tswapal(target_sd->sem_ctime);
@@ -2534,8 +2536,10 @@ static inline abi_long host_to_target_semid_ds(abi_ulong target_addr,
 
     if (!lock_user_struct(VERIFY_WRITE, target_sd, target_addr, 0))
         return -TARGET_EFAULT;
-    if (host_to_target_ipc_perm(target_addr,&(host_sd->sem_perm)))
+    if (host_to_target_ipc_perm(target_addr, &(host_sd->sem_perm))) {
+        unlock_user_struct(target_sd, target_addr, 0);
         return -TARGET_EFAULT;
+    }
     target_sd->sem_nsems = tswapal(host_sd->sem_nsems);
     target_sd->sem_otime = tswapal(host_sd->sem_otime);
     target_sd->sem_ctime = tswapal(host_sd->sem_ctime);
@@ -2796,8 +2800,10 @@ static inline abi_long target_to_host_msqid_ds(struct msqid_ds *host_md,
 
     if (!lock_user_struct(VERIFY_READ, target_md, target_addr, 1))
         return -TARGET_EFAULT;
-    if (target_to_host_ipc_perm(&(host_md->msg_perm),target_addr))
+    if (target_to_host_ipc_perm(&(host_md->msg_perm), target_addr)) {
+        unlock_user_struct(target_md, target_addr, 0);
         return -TARGET_EFAULT;
+    }
     host_md->msg_stime = tswapal(target_md->msg_stime);
     host_md->msg_rtime = tswapal(target_md->msg_rtime);
     host_md->msg_ctime = tswapal(target_md->msg_ctime);
@@ -2817,8 +2823,10 @@ static inline abi_long host_to_target_msqid_ds(abi_ulong target_addr,
 
     if (!lock_user_struct(VERIFY_WRITE, target_md, target_addr, 0))
         return -TARGET_EFAULT;
-    if (host_to_target_ipc_perm(target_addr,&(host_md->msg_perm)))
+    if (host_to_target_ipc_perm(target_addr, &(host_md->msg_perm))) {
+        unlock_user_struct(target_md, target_addr, 0);
         return -TARGET_EFAULT;
+    }
     target_md->msg_stime = tswapal(host_md->msg_stime);
     target_md->msg_rtime = tswapal(host_md->msg_rtime);
     target_md->msg_ctime = tswapal(host_md->msg_ctime);
@@ -2953,8 +2961,7 @@ static inline abi_long do_msgrcv(int msqid, abi_long msgp,
     target_mb->mtype = tswapal(host_mb->mtype);
 
 end:
-    if (target_mb)
-        unlock_user_struct(target_mb, msgp, 1);
+    unlock_user_struct(target_mb, msgp, 1);
     g_free(host_mb);
     return ret;
 }
@@ -2966,8 +2973,10 @@ static inline abi_long target_to_host_shmid_ds(struct shmid_ds *host_sd,
 
     if (!lock_user_struct(VERIFY_READ, target_sd, target_addr, 1))
         return -TARGET_EFAULT;
-    if (target_to_host_ipc_perm(&(host_sd->shm_perm), target_addr))
+    if (target_to_host_ipc_perm(&(host_sd->shm_perm), target_addr)) {
+        unlock_user_struct(target_sd, target_addr, 0);
         return -TARGET_EFAULT;
+    }
     __get_user(host_sd->shm_segsz, &target_sd->shm_segsz);
     __get_user(host_sd->shm_atime, &target_sd->shm_atime);
     __get_user(host_sd->shm_dtime, &target_sd->shm_dtime);
@@ -2986,8 +2995,10 @@ static inline abi_long host_to_target_shmid_ds(abi_ulong target_addr,
 
     if (!lock_user_struct(VERIFY_WRITE, target_sd, target_addr, 0))
         return -TARGET_EFAULT;
-    if (host_to_target_ipc_perm(target_addr, &(host_sd->shm_perm)))
+    if (host_to_target_ipc_perm(target_addr, &(host_sd->shm_perm))) {
+        unlock_user_struct(target_sd, target_addr, 0);
         return -TARGET_EFAULT;
+    }
     __put_user(host_sd->shm_segsz, &target_sd->shm_segsz);
     __put_user(host_sd->shm_atime, &target_sd->shm_atime);
     __put_user(host_sd->shm_dtime, &target_sd->shm_dtime);
-- 
1.9.3

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

end of thread, other threads:[~2015-02-04 22:56 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-01-25 12:06 [Qemu-devel] [PATCH] linux-user/syscall.c: Let all lock_user_struct() and unlock_user_struct() paired with each other Chen Gang S
2015-01-25 12:49 ` Peter Maydell
2015-01-25 21:59   ` Chen Gang S
2015-01-25 22:10     ` Peter Maydell
2015-01-26 14:59       ` Chen Gang S
2015-01-26 15:01         ` Peter Maydell
2015-01-26 23:02           ` Chen Gang S
2015-01-28 14:27           ` Riku Voipio
2015-01-28 22:09             ` Chen Gang S
2015-01-28 22:36               ` Peter Maydell
2015-01-29  1:37                 ` Chen Gang S
2015-02-04 23:03                   ` Chen Gang S

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).