Received: from eggs.gnu.org ([2001:4830:134:3::10]:59548) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1V3lBv-0005FM-2s for qemu-devel@nongnu.org; Mon, 29 Jul 2013 07:00:42 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1V3lBs-0003o6-33 for qemu-devel@nongnu.org; Mon, 29 Jul 2013 07:00:38 -0400 Received: from 1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.d.1.0.0.b.8.0.1.0.0.2.ip6.arpa ([2001:8b0:1d0::1]:59010 helo=mnementh.archaic.org.uk) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1V3lBr-0003nz-Qx for qemu-devel@nongnu.org; Mon, 29 Jul 2013 07:00:35 -0400 From: Peter Maydell Date: Mon, 29 Jul 2013 12:00:32 +0100 Message-Id: <1375095632-13735-3-git-send-email-peter.maydell@linaro.org> In-Reply-To: <1375095632-13735-1-git-send-email-peter.maydell@linaro.org> References: <1375095632-13735-1-git-send-email-peter.maydell@linaro.org> Subject: [Qemu-devel] [PATCH for-1.6 2/2] linux-user/signal.c: Avoid using uninitialized data in ARM sigreturn List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Anthony Liguori , Riku Voipio , qemu-ppc@nongnu.org, Alexander Graf , patches@linaro.org Rephrase code used in ARM sigreturn functions to avoid using uninitialized variables. This fixes one genuine problem ('frame' would not be initialized if we took the error-exit path because our stackpointer was misaligned) and one which is clang being alarmist (frame_addr wouldn't be initialized, though this is harmless since unlock_user_struct ignores its second argument in these cases; however since we don't generally make use of this not-really-documented effect it's better avoided). Signed-off-by: Peter Maydell --- linux-user/signal.c | 36 ++++++++++++++++++++---------------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/linux-user/signal.c b/linux-user/signal.c index d63777d..23d65da 100644 --- a/linux-user/signal.c +++ b/linux-user/signal.c @@ -1552,7 +1552,7 @@ restore_sigcontext(CPUARMState *env, struct target_sigcontext *sc) static long do_sigreturn_v1(CPUARMState *env) { abi_ulong frame_addr; - struct sigframe_v1 *frame; + struct sigframe_v1 *frame = NULL; target_sigset_t set; sigset_t host_set; int i; @@ -1562,10 +1562,11 @@ static long do_sigreturn_v1(CPUARMState *env) * then 'sp' should be word aligned here. If it's * not, then the user is trying to mess with us. */ - if (env->regs[13] & 7) - goto badframe; - frame_addr = env->regs[13]; + if (frame_addr & 7) { + goto badframe; + } + if (!lock_user_struct(VERIFY_READ, frame, frame_addr, 1)) goto badframe; @@ -1693,17 +1694,18 @@ static int do_sigframe_return_v2(CPUARMState *env, target_ulong frame_addr, static long do_sigreturn_v2(CPUARMState *env) { abi_ulong frame_addr; - struct sigframe_v2 *frame; + struct sigframe_v2 *frame = NULL; /* * Since we stacked the signal on a 64-bit boundary, * then 'sp' should be word aligned here. If it's * not, then the user is trying to mess with us. */ - if (env->regs[13] & 7) - goto badframe; - frame_addr = env->regs[13]; + if (frame_addr & 7) { + goto badframe; + } + if (!lock_user_struct(VERIFY_READ, frame, frame_addr, 1)) goto badframe; @@ -1731,7 +1733,7 @@ long do_sigreturn(CPUARMState *env) static long do_rt_sigreturn_v1(CPUARMState *env) { abi_ulong frame_addr; - struct rt_sigframe_v1 *frame; + struct rt_sigframe_v1 *frame = NULL; sigset_t host_set; /* @@ -1739,10 +1741,11 @@ static long do_rt_sigreturn_v1(CPUARMState *env) * then 'sp' should be word aligned here. If it's * not, then the user is trying to mess with us. */ - if (env->regs[13] & 7) - goto badframe; - frame_addr = env->regs[13]; + if (frame_addr & 7) { + goto badframe; + } + if (!lock_user_struct(VERIFY_READ, frame, frame_addr, 1)) goto badframe; @@ -1772,17 +1775,18 @@ badframe: static long do_rt_sigreturn_v2(CPUARMState *env) { abi_ulong frame_addr; - struct rt_sigframe_v2 *frame; + struct rt_sigframe_v2 *frame = NULL; /* * Since we stacked the signal on a 64-bit boundary, * then 'sp' should be word aligned here. If it's * not, then the user is trying to mess with us. */ - if (env->regs[13] & 7) - goto badframe; - frame_addr = env->regs[13]; + if (frame_addr & 7) { + goto badframe; + } + if (!lock_user_struct(VERIFY_READ, frame, frame_addr, 1)) goto badframe; -- 1.7.9.5