From patchwork Sun Jun 29 12:14:47 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Riku Voipio X-Patchwork-Id: 32674 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-vc0-f199.google.com (mail-vc0-f199.google.com [209.85.220.199]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id D2CAF23577 for ; Sun, 29 Jun 2014 12:21:10 +0000 (UTC) Received: by mail-vc0-f199.google.com with SMTP id ij19sf13877001vcb.10 for ; Sun, 29 Jun 2014 05:21:10 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:date :message-id:in-reply-to:references:cc:subject:precedence:list-id :list-unsubscribe:list-archive:list-post:list-help:list-subscribe :errors-to:sender:x-original-sender :x-original-authentication-results:mailing-list; bh=3Fjm0x8xZRV4XMR33o55kuXcIpG5Nc9pjO5nkD1ok0E=; b=X7/xdv3d58N0eGX9sBYc7hxiYUUNkEOQxmnE0M/wdmdbCL8EAejuoOQ6hpztLKy+FO F0gz+v+5EkjPrVgsH0UFTREGBiv35fZmAgwLNQ276ovdh2f36jCy3mKe1qaPLKixJ7iZ FZZFVSd6w3T+3EhFHXQdFJJzaORxBmWhXSybo+xRzJYwz1ugJXEunK5kIpJ/fP2rnnRD 93qG4n51DjkznwpYgNdzLfkUeZG6WzNS1H3+k067RsYfSVdgc3x0WW+EJlVFbKd04uOa E36XpjmprTudVDsi20LPMuogm/DmEo26qdtTohdeCJKLurpOtcmoTlH0wCI/Qz8PwmVS JdZQ== X-Gm-Message-State: ALoCoQmK7ruA0MX84X6NyUU9K2JRR+g1J5sk5QD78Gon0G09GA7iW4vfim1mmPidAaNswV8/RyJX X-Received: by 10.58.160.72 with SMTP id xi8mr19599083veb.15.1404044470655; Sun, 29 Jun 2014 05:21:10 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.25.70 with SMTP id 64ls1148795qgs.14.gmail; Sun, 29 Jun 2014 05:21:10 -0700 (PDT) X-Received: by 10.220.167.2 with SMTP id o2mr32279799vcy.8.1404044470442; Sun, 29 Jun 2014 05:21:10 -0700 (PDT) Received: from mail-vc0-f179.google.com (mail-vc0-f179.google.com [209.85.220.179]) by mx.google.com with ESMTPS id lg9si8817321vdb.3.2014.06.29.05.21.10 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Sun, 29 Jun 2014 05:21:10 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.179 as permitted sender) client-ip=209.85.220.179; Received: by mail-vc0-f179.google.com with SMTP id id10so6537431vcb.38 for ; Sun, 29 Jun 2014 05:21:10 -0700 (PDT) X-Received: by 10.220.105.136 with SMTP id t8mr32032745vco.13.1404044470361; Sun, 29 Jun 2014 05:21:10 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.221.37.5 with SMTP id tc5csp72555vcb; Sun, 29 Jun 2014 05:21:10 -0700 (PDT) X-Received: by 10.140.105.163 with SMTP id c32mr48224487qgf.85.1404044469852; Sun, 29 Jun 2014 05:21:09 -0700 (PDT) Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id a5si20972000qcl.14.2014.06.29.05.21.09 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Sun, 29 Jun 2014 05:21:09 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) client-ip=2001:4830:134:3::11; Received: from localhost ([::1]:57553 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1X1E6X-0006WL-FG for patch@linaro.org; Sun, 29 Jun 2014 08:21:09 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47633) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1X1E0g-00049o-Lx for qemu-devel@nongnu.org; Sun, 29 Jun 2014 08:15:11 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1X1E0X-0000cF-T2 for qemu-devel@nongnu.org; Sun, 29 Jun 2014 08:15:06 -0400 Received: from [2001:4b98:dc0:45:216:3eff:fe3d:166f] (port=41889 helo=afflict.kos.to) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1X1E0X-0000bG-Gp for qemu-devel@nongnu.org; Sun, 29 Jun 2014 08:14:57 -0400 Received: from afflict.kos.to (afflict [92.243.29.197]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by afflict.kos.to (Postfix) with ESMTPSA id 228592657B; Sun, 29 Jun 2014 14:14:56 +0200 (CEST) From: riku.voipio@linaro.org To: qemu-devel@nongnu.org Date: Sun, 29 Jun 2014 15:14:47 +0300 Message-Id: <356d771b30071b44fcb19d2f8d911784b9b276be.1404041926.git.riku.voipio@linaro.org> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: References: X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 2001:4b98:dc0:45:216:3eff:fe3d:166f Cc: Peter Maydell , Anthony Liguori , Paul Burton Subject: [Qemu-devel] [PULL v2 07/13] linux-user: allow NULL arguments to mount X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: , List-Help: , List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: riku.voipio@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.179 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 From: Paul Burton Calls to the mount syscall can legitimately provide NULL as the value for the source of filesystemtype arguments, which QEMU would previously reject & return -EFAULT to the target program. An example of this is remounting an already mounted filesystem with different properties. Instead of rejecting such syscalls with -EFAULT, pass NULL along to the kernel as the target program expects. Additionally this patch fixes a potential memory leak when DEBUG_REMAP is enabled and lock_user_string fails on the target or filesystemtype arguments but a prior argument was non-NULL and already locked. Since the patch already touched most lines of the TARGET_NR_mount case, it fixes the indentation & coding style for good measure. Signed-off-by: Paul Burton Signed-off-by: Riku Voipio --- linux-user/syscall.c | 75 +++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 53 insertions(+), 22 deletions(-) diff --git a/linux-user/syscall.c b/linux-user/syscall.c index 3971cb5..4e48af6 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -5614,29 +5614,60 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1, break; #endif case TARGET_NR_mount: - { - /* need to look at the data field */ - void *p2, *p3; - p = lock_user_string(arg1); - p2 = lock_user_string(arg2); - p3 = lock_user_string(arg3); - if (!p || !p2 || !p3) - ret = -TARGET_EFAULT; - else { - /* FIXME - arg5 should be locked, but it isn't clear how to - * do that since it's not guaranteed to be a NULL-terminated - * string. - */ - if ( ! arg5 ) - ret = get_errno(mount(p, p2, p3, (unsigned long)arg4, NULL)); - else - ret = get_errno(mount(p, p2, p3, (unsigned long)arg4, g2h(arg5))); - } + { + /* need to look at the data field */ + void *p2, *p3; + + if (arg1) { + p = lock_user_string(arg1); + if (!p) { + goto efault; + } + } else { + p = NULL; + } + + p2 = lock_user_string(arg2); + if (!p2) { + if (arg1) { + unlock_user(p, arg1, 0); + } + goto efault; + } + + if (arg3) { + p3 = lock_user_string(arg3); + if (!p3) { + if (arg1) { unlock_user(p, arg1, 0); - unlock_user(p2, arg2, 0); - unlock_user(p3, arg3, 0); - break; - } + } + unlock_user(p2, arg2, 0); + goto efault; + } + } else { + p3 = NULL; + } + + /* FIXME - arg5 should be locked, but it isn't clear how to + * do that since it's not guaranteed to be a NULL-terminated + * string. + */ + if (!arg5) { + ret = mount(p, p2, p3, (unsigned long)arg4, NULL); + } else { + ret = mount(p, p2, p3, (unsigned long)arg4, g2h(arg5)); + } + ret = get_errno(ret); + + if (arg1) { + unlock_user(p, arg1, 0); + } + unlock_user(p2, arg2, 0); + if (arg3) { + unlock_user(p3, arg3, 0); + } + } + break; #ifdef TARGET_NR_umount case TARGET_NR_umount: if (!(p = lock_user_string(arg1)))