From patchwork Mon Jun 23 13:26:23 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Riku Voipio X-Patchwork-Id: 32368 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wg0-f70.google.com (mail-wg0-f70.google.com [74.125.82.70]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id BB2D0203AC for ; Mon, 23 Jun 2014 14:33:01 +0000 (UTC) Received: by mail-wg0-f70.google.com with SMTP id b13sf4036926wgh.9 for ; Mon, 23 Jun 2014 07:33:00 -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=yTssjm+temehCVk5uFj6U1Fp06UToPYOKmS06xhVv1w=; b=g17R+Q88WNZZ5mppfMAl5H6/WG4gP/vAmfynChDnME6fiMGMJ7IIx5igvTZwVICBiv 42YgvMoJfIzqEmxYfVf/FaqzvsZXqtdMJ38nYwjhG2G2FHzhHmxy2HAnhXYA/4oNVGsY Yiub/zDZiVsRs5U6gwVD8bZ4zseP72AgS2ptaIDWoqoByKVg5pLmo1r1dLBiasRL1H5X XNPyMTdDYM2qN2TXgnpQ54TCUXhMsp8xJUrdScCXstPUYFAUrjplWkBZF1FAEi8H8+/v qkmzaaJfiHP2eFoKmPHNeI4Urbe7b/8DUyOI+pbo2P3jlJ14tXpuIKjtSgq5y8WXeW1j o40A== X-Gm-Message-State: ALoCoQlr0QlXcSx9peU+OmULlf1fyXhQgLqlR7dK3AzrIqq3loijiiHI/Lrj3r4Eiv4BCdkq3HIs X-Received: by 10.112.13.36 with SMTP id e4mr417794lbc.11.1403533980604; Mon, 23 Jun 2014 07:33:00 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.94.129 with SMTP id g1ls1945365qge.17.gmail; Mon, 23 Jun 2014 07:32:59 -0700 (PDT) X-Received: by 10.58.186.78 with SMTP id fi14mr838994vec.73.1403533979949; Mon, 23 Jun 2014 07:32:59 -0700 (PDT) Received: from mail-ve0-f169.google.com (mail-ve0-f169.google.com [209.85.128.169]) by mx.google.com with ESMTPS id so6si9091384vdb.76.2014.06.23.07.32.59 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 23 Jun 2014 07:32:59 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.128.169 as permitted sender) client-ip=209.85.128.169; Received: by mail-ve0-f169.google.com with SMTP id pa12so6215328veb.14 for ; Mon, 23 Jun 2014 07:32:59 -0700 (PDT) X-Received: by 10.58.46.34 with SMTP id s2mr1200132vem.49.1403533979871; Mon, 23 Jun 2014 07:32:59 -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 tc5csp135091vcb; Mon, 23 Jun 2014 07:32:59 -0700 (PDT) X-Received: by 10.140.82.113 with SMTP id g104mr32075718qgd.55.1403533979214; Mon, 23 Jun 2014 07:32:59 -0700 (PDT) Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id y19si13700718qae.27.2014.06.23.07.32.59 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Mon, 23 Jun 2014 07:32:59 -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]:53515 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Wz4K7-0000AU-MS for patch@linaro.org; Mon, 23 Jun 2014 09:30:15 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:55667) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Wz4Gm-0003iN-Qw for qemu-devel@nongnu.org; Mon, 23 Jun 2014 09:26:54 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Wz4Gd-0001Bg-LW for qemu-devel@nongnu.org; Mon, 23 Jun 2014 09:26:48 -0400 Received: from [2001:4b98:dc0:45:216:3eff:fe3d:166f] (port=37360 helo=afflict.kos.to) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Wz4Gd-0001AW-Cg for qemu-devel@nongnu.org; Mon, 23 Jun 2014 09:26:39 -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 4729326581; Mon, 23 Jun 2014 15:26:36 +0200 (CEST) From: riku.voipio@linaro.org To: qemu-devel@nongnu.org Date: Mon, 23 Jun 2014 16:26:23 +0300 Message-Id: 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: Paul Burton Subject: [Qemu-devel] [PULL 08/19] 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.128.169 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)))