From patchwork Mon Nov 20 21:21:29 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Riku Voipio X-Patchwork-Id: 10067307 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 3ABD96038F for ; Mon, 20 Nov 2017 21:23:18 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2DF0D290C5 for ; Mon, 20 Nov 2017 21:23:18 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 22BB029242; Mon, 20 Nov 2017 21:23:18 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id D7EF0290C5 for ; Mon, 20 Nov 2017 21:23:15 +0000 (UTC) Received: from localhost ([::1]:59803 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eGtX8-0004WH-MD for patchwork-qemu-devel@patchwork.kernel.org; Mon, 20 Nov 2017 16:23:14 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58093) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eGtVn-0004Tc-1s for qemu-devel@nongnu.org; Mon, 20 Nov 2017 16:21:52 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eGtVk-0007dx-Bu for qemu-devel@nongnu.org; Mon, 20 Nov 2017 16:21:51 -0500 Received: from mail-lf0-x244.google.com ([2a00:1450:4010:c07::244]:36361) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1eGtVk-0007ca-4L for qemu-devel@nongnu.org; Mon, 20 Nov 2017 16:21:48 -0500 Received: by mail-lf0-x244.google.com with SMTP id k66so11726548lfg.3 for ; Mon, 20 Nov 2017 13:21:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=sxp7NkQJ0fCFMZAWQwuA4SBV3gox/kUeV3nqW9idGoY=; b=T9nYiPQYIxhJxPe3KxV1JcUGo2oClZAbsAAv8PH3nJaU0joWQJmbJVBN0OXxRiRYkt 00ekHuzvwcZOOrI/S8J+zAinvXE8Zt+FJr8oaqEC/9CSb5lMexbKnMVZTTP8tsGYy6jc 2XzoM9r5dKfmiFTu+lvnDSTv8juj8Ahj+by7I= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=sxp7NkQJ0fCFMZAWQwuA4SBV3gox/kUeV3nqW9idGoY=; b=O9sdpMV90cprMjKU/CyjVJeQOXdtIW9n8jzPHFxub9fWJ7KyI84e2kaRHiEbLupCu7 MODT4ZzJWR2IiVp415+xBEgbSx7udHn4UYHerlF98bXOAMjV+FMP41QJws32K+vZUxTR yOOeUa+SaaACzU4NghnqJITBmso160Pw12EV7NzK6b9+HiyAWkDnAlO+C1kNhZooRPUA DXKf7s1Vy0L4XPl/KfBkLY9tw5ZpA6SnPA1yc3n5c3QwdW7t7o03TcnvO/TOSzZlC+pb 6TmaViaMmURxS7ldrmKCcWxuI6nUWxZt9FIXRl2fYdGqphsmeB67hi8+VS2JaHSVLNJO upRg== X-Gm-Message-State: AJaThX7CvfSdjQ34kCFNnSCAqoBoLT4NL4nmIZQ8G/3jfzD5jJdVBEPJ aUQ/huiDc36FGvQAqJ1KtIByQT6u8nA= X-Google-Smtp-Source: AGs4zMYMPfyX1tiuXCQm/a57TeCGCgQ8Dfgm0yYVxNDsXuaZG/Fq3DRNxiY+Li64qgbVCJTW9ZrCeg== X-Received: by 10.46.89.196 with SMTP id g65mr4643315ljf.53.1511212906573; Mon, 20 Nov 2017 13:21:46 -0800 (PST) Received: from beaming.home (91-157-170-157.elisa-laajakaista.fi. [91.157.170.157]) by smtp.gmail.com with ESMTPSA id v63sm1645409lje.39.2017.11.20.13.21.45 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 20 Nov 2017 13:21:45 -0800 (PST) From: riku.voipio@linaro.org To: qemu-devel@nongnu.org Date: Mon, 20 Nov 2017 23:21:29 +0200 Message-Id: <7f047de18cf6cd51915d4fdbe1a7e66c38b45e98.1511212753.git.riku.voipio@linaro.org> X-Mailer: git-send-email 2.14.2 In-Reply-To: References: X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4010:c07::244 Subject: [Qemu-devel] [PULL 01/15] linux-user: Restrict usage of sa_restorer X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Richard Henderson Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Richard Henderson Reading and writing to an sa_restorer member that isn't supposed to exist corrupts user memory. Introduce TARGET_ARCH_HAS_SA_RESTORER, similar to the kernel's __ARCH_HAS_SA_RESTORER. Reported-by: Helge Deller Signed-off-by: Richard Henderson Signed-off-by: Riku Voipio --- linux-user/signal.c | 4 ++-- linux-user/syscall_defs.h | 13 +++++++++++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/linux-user/signal.c b/linux-user/signal.c index 7a238aaea1..cf35473671 100644 --- a/linux-user/signal.c +++ b/linux-user/signal.c @@ -777,7 +777,7 @@ int do_sigaction(int sig, const struct target_sigaction *act, if (oact) { __put_user(k->_sa_handler, &oact->_sa_handler); __put_user(k->sa_flags, &oact->sa_flags); -#if !defined(TARGET_MIPS) +#ifdef TARGET_ARCH_HAS_SA_RESTORER __put_user(k->sa_restorer, &oact->sa_restorer); #endif /* Not swapped. */ @@ -787,7 +787,7 @@ int do_sigaction(int sig, const struct target_sigaction *act, /* FIXME: This is not threadsafe. */ __get_user(k->_sa_handler, &act->_sa_handler); __get_user(k->sa_flags, &act->sa_flags); -#if !defined(TARGET_MIPS) +#ifdef TARGET_ARCH_HAS_SA_RESTORER __get_user(k->sa_restorer, &act->sa_restorer); #endif /* To be swapped in target_to_host_sigset. */ diff --git a/linux-user/syscall_defs.h b/linux-user/syscall_defs.h index 450960bb54..e366183419 100644 --- a/linux-user/syscall_defs.h +++ b/linux-user/syscall_defs.h @@ -445,6 +445,7 @@ int do_sigaction(int sig, const struct target_sigaction *act, #define TARGET_SA_RESTART 2u #define TARGET_SA_NODEFER 0x20u #define TARGET_SA_RESETHAND 4u +#define TARGET_ARCH_HAS_SA_RESTORER 1 #elif defined(TARGET_MIPS) #define TARGET_SA_NOCLDSTOP 0x00000001 #define TARGET_SA_NOCLDWAIT 0x00010000 @@ -483,6 +484,10 @@ int do_sigaction(int sig, const struct target_sigaction *act, #define TARGET_SA_RESTORER 0x04000000 #endif +#ifdef TARGET_SA_RESTORER +#define TARGET_ARCH_HAS_SA_RESTORER 1 +#endif + #if defined(TARGET_ALPHA) #define TARGET_SIGHUP 1 @@ -718,19 +723,27 @@ struct target_sigaction { abi_ulong _sa_handler; #endif target_sigset_t sa_mask; +#ifdef TARGET_ARCH_HAS_SA_RESTORER + /* ??? This is always present, but ignored unless O32. */ + abi_ulong sa_restorer; +#endif }; #else struct target_old_sigaction { abi_ulong _sa_handler; abi_ulong sa_mask; abi_ulong sa_flags; +#ifdef TARGET_ARCH_HAS_SA_RESTORER abi_ulong sa_restorer; +#endif }; struct target_sigaction { abi_ulong _sa_handler; abi_ulong sa_flags; +#ifdef TARGET_ARCH_HAS_SA_RESTORER abi_ulong sa_restorer; +#endif target_sigset_t sa_mask; }; #endif