From patchwork Sat Jun 2 21:29:35 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Keno Fischer X-Patchwork-Id: 924607 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=juliacomputing.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=juliacomputing-com.20150623.gappssmtp.com header.i=@juliacomputing-com.20150623.gappssmtp.com header.b="wD8StwQq"; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 40yvbd4MwRz9s0x for ; Sun, 3 Jun 2018 07:34:21 +1000 (AEST) Received: from localhost ([::1]:32851 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fPEAF-0001qP-8s for incoming@patchwork.ozlabs.org; Sat, 02 Jun 2018 17:34:19 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44432) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fPE6y-0007wZ-I4 for qemu-devel@nongnu.org; Sat, 02 Jun 2018 17:30:58 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fPE6u-0005lj-H4 for qemu-devel@nongnu.org; Sat, 02 Jun 2018 17:30:56 -0400 Received: from mail-qk0-x243.google.com ([2607:f8b0:400d:c09::243]:33963) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fPE6u-0005lQ-B1 for qemu-devel@nongnu.org; Sat, 02 Jun 2018 17:30:52 -0400 Received: by mail-qk0-x243.google.com with SMTP id q70-v6so13894775qke.1 for ; Sat, 02 Jun 2018 14:30:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=juliacomputing-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=si7VNUK4mI3QWawkK5K75wtjdteYW0WFYdUqAuNTNI4=; b=wD8StwQqyJZ6rE8iyMrUSY7q1GiTHGKBuxPLi6+sz1YrMp878Etd5gPxniW2bISeBo w7h9wjzZetB4jMWidyaZMxgtuqnH0nJaUX7zFhkrh15+W5GnNxLUZimiCvQxCnHtedZb wPW0mpz+/AsJY84DJFM6yzIaYB+A1iJEawclAuA5/Zetr2lKGp9v5/deopQ3EEqYIAFt mME9Aq2RHjXsER3cijeK8rq7GoFgIKh3a01Ke9K/YZS5f+7CvVrN8lcmYx9l8Kl6I8qP 17aNrWMBXrctoOfX6wvyvamr3t7io+JALTF9rNXMwpe1os1MQt1Jb/iAvLNnHFQ5Qqz9 Nhpg== 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:in-reply-to:references; bh=si7VNUK4mI3QWawkK5K75wtjdteYW0WFYdUqAuNTNI4=; b=I4UkEdIi6UNoC+U+p9XTymWS/mPcXyONcXkQRMthFTFHOdqXgeYUesKD1WCWwJucBa GIsnIw3Ka0UPPpfHn/gIEBDL+xEXYlsBJ71+M9tTJ2VfA3v5Y1+5kX9giCF+k9j+LMsw NqEn1A7yScxEuuFtxMri56NO3n6VVEwWGJklz9na8nc8tO7ipPvLt1lMImScfu5qast2 BXTpGXstkG8Gz1R7yUGvRULZbbgi+jGztyxBpw4UJv1Gkm1xys4uv7t6KZjrBa+SEsCP 4AIDNSYbKjFElh1/V3blXjAqFOr74VLBgltL63vIqbkhEGzEsjGWGL39DLoDjI+NZWpI MrCg== X-Gm-Message-State: APt69E0ZeQnwFm66Zkh3uBaVtkN7790X19XAU7NFij2TfURbCSo2y95q Qq+lKp9Fq/bABQeyaQwgqgHDachLF+k= X-Google-Smtp-Source: ADUXVKIlXHQXq9Hs1k6unFAjAg+yHHnzbUG/bd+m4y+Lc0c5sCiY9aamsuj9KdTKPlqzCL1r1k8UfQ== X-Received: by 2002:a37:6ac6:: with SMTP id f189-v6mr6205388qkc.169.1527975051289; Sat, 02 Jun 2018 14:30:51 -0700 (PDT) Received: from localhost.localdomain (96-86-104-61-static.hfc.comcastbusiness.net. [96.86.104.61]) by smtp.gmail.com with ESMTPSA id k2-v6sm21366628qkl.95.2018.06.02.14.30.49 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sat, 02 Jun 2018 14:30:50 -0700 (PDT) From: Keno Fischer To: qemu-devel@nongnu.org Date: Sat, 2 Jun 2018 17:29:35 -0400 Message-Id: <51be4c123dbf92a45184e386bd7a62614430ba29.1527973524.git.keno@juliacomputing.com> X-Mailer: git-send-email 2.8.1 In-Reply-To: References: In-Reply-To: References: X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:400d:c09::243 Subject: [Qemu-devel] [PATCH v3 1/5] cutils: Provide strchrnul 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: Keno Fischer , groug@kaod.org, "Dr. David Alan Gilbert" , Markus Armbruster Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" strchrnul is a GNU extension and thus unavailable on a number of targets. In the review for a commit removing strchrnul from 9p, I was asked to create a qemu_strchrnul helper to factor out this functionality. Do so, and use it in a number of other places in the code base that inlined the replacement pattern in a place where strchrnul could be used. Signed-off-by: Keno Fischer Acked-by: Greg Kurz --- Changes since v2: * Add configure check as suggested by Greg Kurz , and requested by Eric Blake * Use qemu_strchrnul in hmp_sendkey as suggested by Dr. David Alan Gilbert configure | 15 +++++++++++++++ hmp.c | 8 ++++---- hw/9pfs/9p-local.c | 2 +- include/qemu/cutils.h | 8 ++++++++ monitor.c | 8 ++------ util/cutils.c | 15 +++++++++++++++ util/qemu-option.c | 6 +----- util/uri.c | 6 ++---- 8 files changed, 48 insertions(+), 20 deletions(-) diff --git a/configure b/configure index a6a4616..1b3ca4e 100755 --- a/configure +++ b/configure @@ -4754,6 +4754,18 @@ if compile_prog "" "" ; then fi ########################################## +# check if we have strchrnul + +strchrnul=no +cat > $TMPC << EOF +#include +int main(void) { (void)strchrnul("Hello World", 'W'); } +EOF +if compile_prog "" "" ; then + strchrnul=yes +fi + +########################################## # check if trace backend exists $python "$source_path/scripts/tracetool.py" "--backends=$trace_backends" --check-backends > /dev/null 2> /dev/null @@ -6210,6 +6222,9 @@ fi if test "$sem_timedwait" = "yes" ; then echo "CONFIG_SEM_TIMEDWAIT=y" >> $config_host_mak fi +if test "$strchrnul" = "yes" ; then + echo "CONFIG_STRCHRNUL=y" >> $config_host_mak +fi if test "$byteswap_h" = "yes" ; then echo "CONFIG_BYTESWAP_H=y" >> $config_host_mak fi diff --git a/hmp.c b/hmp.c index ef93f48..416d4c9 100644 --- a/hmp.c +++ b/hmp.c @@ -2123,12 +2123,12 @@ void hmp_sendkey(Monitor *mon, const QDict *qdict) int has_hold_time = qdict_haskey(qdict, "hold-time"); int hold_time = qdict_get_try_int(qdict, "hold-time", -1); Error *err = NULL; - char *separator; + const char *separator; int keyname_len; while (1) { - separator = strchr(keys, '-'); - keyname_len = separator ? separator - keys : strlen(keys); + separator = qemu_strchrnul(keys, '-'); + keyname_len = separator - keys; /* Be compatible with old interface, convert user inputted "<" */ if (keys[0] == '<' && keyname_len == 1) { @@ -2165,7 +2165,7 @@ void hmp_sendkey(Monitor *mon, const QDict *qdict) keylist->value->u.qcode.data = idx; } - if (!separator) { + if (!*separator) { break; } keys = separator + 1; diff --git a/hw/9pfs/9p-local.c b/hw/9pfs/9p-local.c index 7758c38..304ef72 100644 --- a/hw/9pfs/9p-local.c +++ b/hw/9pfs/9p-local.c @@ -65,7 +65,7 @@ int local_open_nofollow(FsContext *fs_ctx, const char *path, int flags, assert(*path != '/'); head = g_strdup(path); - c = strchrnul(path, '/'); + c = qemu_strchrnul(path, '/'); if (*c) { /* Intermediate path element */ head[c - path] = 0; diff --git a/include/qemu/cutils.h b/include/qemu/cutils.h index a663340..809090c 100644 --- a/include/qemu/cutils.h +++ b/include/qemu/cutils.h @@ -122,6 +122,14 @@ int qemu_strnlen(const char *s, int max_len); * Returns: the pointer originally in @input. */ char *qemu_strsep(char **input, const char *delim); +#ifdef CONFIG_STRCHRNUL +static inline const char *qemu_strchrnul(const char *s, int c) +{ + return strchrnul(s, c); +} +#else +const char *qemu_strchrnul(const char *s, int c); +#endif time_t mktimegm(struct tm *tm); int qemu_fdatasync(int fd); int fcntl_setfl(int fd, int flag); diff --git a/monitor.c b/monitor.c index 922cfc0..e1f01c4 100644 --- a/monitor.c +++ b/monitor.c @@ -798,9 +798,7 @@ static int compare_cmd(const char *name, const char *list) p = list; for(;;) { pstart = p; - p = strchr(p, '|'); - if (!p) - p = pstart + strlen(pstart); + p = qemu_strchrnul(p, '|'); if ((p - pstart) == len && !memcmp(pstart, name, len)) return 1; if (*p == '\0') @@ -3401,9 +3399,7 @@ static void cmd_completion(Monitor *mon, const char *name, const char *list) p = list; for(;;) { pstart = p; - p = strchr(p, '|'); - if (!p) - p = pstart + strlen(pstart); + p = qemu_strchrnul(p, '|'); len = p - pstart; if (len > sizeof(cmd) - 2) len = sizeof(cmd) - 2; diff --git a/util/cutils.c b/util/cutils.c index 0de69e6..c365ddb 100644 --- a/util/cutils.c +++ b/util/cutils.c @@ -545,6 +545,21 @@ int qemu_strtou64(const char *nptr, const char **endptr, int base, } /** + * Searches for the first occurrence of 'c' in 's', and returns a pointer + * to the trailing null byte if none was found. + */ +#ifndef CONFIG_STRCHRNUL +const char *qemu_strchrnul(const char *s, int c) +{ + const char *e = strchr(s, c); + if (!e) { + e = s + strlen(s); + } + return e; +} +#endif + +/** * parse_uint: * * @s: String to parse diff --git a/util/qemu-option.c b/util/qemu-option.c index 58d1c23..54eca12 100644 --- a/util/qemu-option.c +++ b/util/qemu-option.c @@ -77,11 +77,7 @@ const char *get_opt_value(const char *p, char **value) *value = NULL; while (1) { - offset = strchr(p, ','); - if (!offset) { - offset = p + strlen(p); - } - + offset = qemu_strchrnul(p, ','); length = offset - p; if (*offset != '\0' && *(offset + 1) == ',') { length++; diff --git a/util/uri.c b/util/uri.c index 8624a7a..8bdef84 100644 --- a/util/uri.c +++ b/util/uri.c @@ -52,6 +52,7 @@ */ #include "qemu/osdep.h" +#include "qemu/cutils.h" #include "qemu/uri.h" @@ -2266,10 +2267,7 @@ struct QueryParams *query_params_parse(const char *query) /* Find the next separator, or end of the string. */ end = strchr(query, '&'); if (!end) { - end = strchr(query, ';'); - } - if (!end) { - end = query + strlen(query); + end = qemu_strchrnul(query, ';'); } /* Find the first '=' character between here and end. */ From patchwork Sat Jun 2 21:29:36 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Keno Fischer X-Patchwork-Id: 924605 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=juliacomputing.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=juliacomputing-com.20150623.gappssmtp.com header.i=@juliacomputing-com.20150623.gappssmtp.com header.b="i+n+yYes"; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 40yvXf5B0qz9s0W for ; Sun, 3 Jun 2018 07:31:46 +1000 (AEST) Received: from localhost ([::1]:32841 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fPE7k-0007zc-8a for incoming@patchwork.ozlabs.org; Sat, 02 Jun 2018 17:31:44 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44433) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fPE6y-0007wa-Hu for qemu-devel@nongnu.org; Sat, 02 Jun 2018 17:30:58 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fPE6v-0005mX-Sr for qemu-devel@nongnu.org; Sat, 02 Jun 2018 17:30:56 -0400 Received: from mail-qk0-x241.google.com ([2607:f8b0:400d:c09::241]:39436) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fPE6v-0005mB-Nu for qemu-devel@nongnu.org; Sat, 02 Jun 2018 17:30:53 -0400 Received: by mail-qk0-x241.google.com with SMTP id g14-v6so10239920qkm.6 for ; Sat, 02 Jun 2018 14:30:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=juliacomputing-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=bRoFQJjx8hbTJfC24YFGa/umDJaiaklsOP2aNQn0suE=; b=i+n+yYesWCPaEjcG2XC16j0a78z1V0ucVMQsf3Y8GBy3RCmP8ViKPocoJCKTM2gQzg UCVfo1w4NpXNeCdRsGvsxSOg2XhyccjK3KPoNEswya1q+Z/cfb54UM1QYEjb7drtq60F Amh7TtcdKyjz521WDr3rAPa34EaBSLt2N2YMm7QaTZ3ceuGJAfhtARk1/rSt5UHxBGec PO0XG2fmPB5VVREoX17Ue3ahE/IXRxQwfVCwz1JIR+Ji4jezrO/JI/nHcb126KKcSx7N hUZcndlN2I3G//V5xayLheQ+QI3DjpCTIilmnogm9Gbzj1TtdpFtf7WwwST1Lg8URpXQ MDoQ== 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:in-reply-to:references; bh=bRoFQJjx8hbTJfC24YFGa/umDJaiaklsOP2aNQn0suE=; b=Ko8J7zszWj5RamVRENf0blu1lZKfOSU408dri7nfvsP4N47SE0UaG3UBzetnxQ1Kuu Q168TFStg7INzlhtRm/k+WgnlVRkhlhLcPs0y9OgmV2/9caQTQsMCDNqJGaKpkWRx310 A4K2YBH/FSoDo7ZLeMn1FKq+EzMYkeSgXQIv8rAeN19ggdOiTNyNcoQw6fI2bZf58iOK fDFijXdnQ9kMtCa5MWz7I3rByMJbFq85c41A1wZDWAwNmYGVPHgQtMfIWXC86BSnVQwD v693zGQ1kTQ09AvoDuXuNoqT2q757n1zanMQWSggO2FGSKfWmy5XvVoPBJyziYxjmA7f RXHA== X-Gm-Message-State: APt69E21+L16mKUqPadDFVvMGtKiHnkzEi+YQtdGNhWmoMpKZ80CgzcW t/DcoaM0qzerg75Pvuaxz9p1PjkLlag= X-Google-Smtp-Source: ADUXVKIwd4/rXyWqK4iOIgSwUQCDE5hPOPaAaF3Z1xo18Aa8y4OZUCZCCSbM2c6gnvW5/BdSJhORKg== X-Received: by 2002:a37:bdc5:: with SMTP id n188-v6mr13697295qkf.12.1527975052746; Sat, 02 Jun 2018 14:30:52 -0700 (PDT) Received: from localhost.localdomain (96-86-104-61-static.hfc.comcastbusiness.net. [96.86.104.61]) by smtp.gmail.com with ESMTPSA id k2-v6sm21366628qkl.95.2018.06.02.14.30.51 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sat, 02 Jun 2018 14:30:51 -0700 (PDT) From: Keno Fischer To: qemu-devel@nongnu.org Date: Sat, 2 Jun 2018 17:29:36 -0400 Message-Id: X-Mailer: git-send-email 2.8.1 In-Reply-To: References: In-Reply-To: References: X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:400d:c09::241 Subject: [Qemu-devel] [PATCH v3 2/5] 9p: xattr: Fix crashes due to free of uninitialized value 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: Keno Fischer , groug@kaod.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" If the size returned from llistxattr/lgetxattr is 0, we skipped the malloc call, leaving xattr.value uninitialized. However, this value is later passed to `g_free` without any further checks, causing an error. Fix that by always calling g_malloc unconditionally. If `size` is 0, it will return NULL, which is safe to pass to g_free. Signed-off-by: Keno Fischer --- Changes since v2: * Fix another instance of the problematic pattern later in the same function. hw/9pfs/9p.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/hw/9pfs/9p.c b/hw/9pfs/9p.c index d74302d..4386d69 100644 --- a/hw/9pfs/9p.c +++ b/hw/9pfs/9p.c @@ -3256,8 +3256,8 @@ static void coroutine_fn v9fs_xattrwalk(void *opaque) xattr_fidp->fs.xattr.len = size; xattr_fidp->fid_type = P9_FID_XATTR; xattr_fidp->fs.xattr.xattrwalk_fid = true; + xattr_fidp->fs.xattr.value = g_malloc0(size); if (size) { - xattr_fidp->fs.xattr.value = g_malloc0(size); err = v9fs_co_llistxattr(pdu, &xattr_fidp->path, xattr_fidp->fs.xattr.value, xattr_fidp->fs.xattr.len); @@ -3289,8 +3289,8 @@ static void coroutine_fn v9fs_xattrwalk(void *opaque) xattr_fidp->fs.xattr.len = size; xattr_fidp->fid_type = P9_FID_XATTR; xattr_fidp->fs.xattr.xattrwalk_fid = true; + xattr_fidp->fs.xattr.value = g_malloc0(size); if (size) { - xattr_fidp->fs.xattr.value = g_malloc0(size); err = v9fs_co_lgetxattr(pdu, &xattr_fidp->path, &name, xattr_fidp->fs.xattr.value, xattr_fidp->fs.xattr.len); From patchwork Sat Jun 2 21:29:37 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Keno Fischer X-Patchwork-Id: 924603 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=juliacomputing.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=juliacomputing-com.20150623.gappssmtp.com header.i=@juliacomputing-com.20150623.gappssmtp.com header.b="jYKjvqQe"; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 40yvXZ2q5Pz9s0W for ; Sun, 3 Jun 2018 07:31:42 +1000 (AEST) Received: from localhost ([::1]:32839 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fPE7g-0007xn-0N for incoming@patchwork.ozlabs.org; Sat, 02 Jun 2018 17:31:40 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44439) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fPE6y-0007wc-Pm for qemu-devel@nongnu.org; Sat, 02 Jun 2018 17:30:58 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fPE6x-0005nZ-LK for qemu-devel@nongnu.org; Sat, 02 Jun 2018 17:30:56 -0400 Received: from mail-qt0-x243.google.com ([2607:f8b0:400d:c0d::243]:44208) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fPE6x-0005nE-HD for qemu-devel@nongnu.org; Sat, 02 Jun 2018 17:30:55 -0400 Received: by mail-qt0-x243.google.com with SMTP id d3-v6so36437707qtp.11 for ; Sat, 02 Jun 2018 14:30:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=juliacomputing-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=2G+S6SvHzcMbaTH0krEmSFLlggs0zoKoJDi1DpZHPvI=; b=jYKjvqQe9+0mDirbBduEHCqTW1dEjH/X70gK0Br8YLntsvUnM+t08AXcqugh3PIWs/ qWUav4GETgYtaXXUPOUUrEN18DNeNgZrTDOhJpmt6lcQ0A2YH/b3m+oaGdPjUj24QZQ1 6QmJ0EAI11CtuY5aBKSUC4QeqAdjwosu/VZWrqd1p2Y/Qgbz4gBvl28t3saeCCNKxEjj yDQkmxkaSGrPxkHWlNPMYf4YtboLLzusIQmHWh0gQj/L4iN23f1QDx6WgQl71hpWLThl 6dKiEuEdqdDkpWrskr7WTLyTrXEeb0HC0vquGtLwVFXD8EUyjVu48jP2ib9EbRQ1N1Fk 1BPQ== 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:in-reply-to:references; bh=2G+S6SvHzcMbaTH0krEmSFLlggs0zoKoJDi1DpZHPvI=; b=LDB5yqop3JB8kp/FYkdC2KxxZF3lEXBBNH5Q+uefIX3ZxpdE/5HJfxN5Ymz/u2MV56 r6rYdrteG5C+2JvNqlkgHUUtuE8XSveZY+4+p3e+yLiAaia3oPjgZjsx9m0Tc1loesYg aRD46uA7xXnhSHNRL3guwyTXXP7wFHTStA3cFZDAfTENsE+nccpcolnbdBln55713+8W f3Vuddk0KYFFJZDCm3QzHw3F9GiudlSNG6Cco1EcrebVWNoM6zvlG249WvWD1eWb+v/S vmDp3cnn0Y81Ez5d/wZkU5n/seD3QAFtec+p04+jCsy+fgS6a5sGBqgCPdwbYOTg0PwX 5ePw== X-Gm-Message-State: APt69E2cC8SGd6rDsjC0w1Rz5ti4Ryr39oUm2n0T8g3CTnFJoMHJgGxp BMIHX9K7Vceg0Q2L3COGVkAgTR2F8U0= X-Google-Smtp-Source: ADUXVKIBbQEG2S8eGVftMfx1FNlxBgs9VdFxpFxkKQPX3DLY0hx7BLQude9UYtczMgtIx1FIWGG17Q== X-Received: by 2002:ac8:235c:: with SMTP id b28-v6mr15500146qtb.212.1527975054460; Sat, 02 Jun 2018 14:30:54 -0700 (PDT) Received: from localhost.localdomain (96-86-104-61-static.hfc.comcastbusiness.net. [96.86.104.61]) by smtp.gmail.com with ESMTPSA id k2-v6sm21366628qkl.95.2018.06.02.14.30.52 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sat, 02 Jun 2018 14:30:53 -0700 (PDT) From: Keno Fischer To: qemu-devel@nongnu.org Date: Sat, 2 Jun 2018 17:29:37 -0400 Message-Id: <15479c7ebdc70dd260f696cd4c3d2d0f2336f375.1527973524.git.keno@juliacomputing.com> X-Mailer: git-send-email 2.8.1 In-Reply-To: References: In-Reply-To: References: X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:400d:c0d::243 Subject: [Qemu-devel] [PATCH v3 3/5] 9p: local: Avoid warning if FS_IOC_GETVERSION is not defined 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: Keno Fischer , groug@kaod.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Both `stbuf` and `local_ioc_getversion` where unused when FS_IOC_GETVERSION was not defined, causing a compiler warning. Reorganize the code to avoid this warning. Signed-off-by: Keno Fischer --- hw/9pfs/9p-local.c | 40 +++++++++++++++++++++++----------------- 1 file changed, 23 insertions(+), 17 deletions(-) diff --git a/hw/9pfs/9p-local.c b/hw/9pfs/9p-local.c index 304ef72..828e8d6 100644 --- a/hw/9pfs/9p-local.c +++ b/hw/9pfs/9p-local.c @@ -1373,10 +1373,10 @@ static int local_unlinkat(FsContext *ctx, V9fsPath *dir, return ret; } +#ifdef FS_IOC_GETVERSION static int local_ioc_getversion(FsContext *ctx, V9fsPath *path, mode_t st_mode, uint64_t *st_gen) { -#ifdef FS_IOC_GETVERSION int err; V9fsFidOpenState fid_open; @@ -1395,32 +1395,21 @@ static int local_ioc_getversion(FsContext *ctx, V9fsPath *path, err = ioctl(fid_open.fd, FS_IOC_GETVERSION, st_gen); local_close(ctx, &fid_open); return err; -#else - errno = ENOTTY; - return -1; -#endif } +#endif -static int local_init(FsContext *ctx, Error **errp) +static int local_ioc_getversion_init(FsContext *ctx, LocalData *data, Error **errp) { +#ifdef FS_IOC_GETVERSION struct statfs stbuf; - LocalData *data = g_malloc(sizeof(*data)); - data->mountfd = open(ctx->fs_root, O_DIRECTORY | O_RDONLY); - if (data->mountfd == -1) { - error_setg_errno(errp, errno, "failed to open '%s'", ctx->fs_root); - goto err; - } - -#ifdef FS_IOC_GETVERSION /* * use ioc_getversion only if the ioctl is definied */ if (fstatfs(data->mountfd, &stbuf) < 0) { - close_preserve_errno(data->mountfd); error_setg_errno(errp, errno, - "failed to stat file system at '%s'", ctx->fs_root); - goto err; + "failed to stat file system at '%s'", ctx->fs_root); + return -1; } switch (stbuf.f_type) { case EXT2_SUPER_MAGIC: @@ -1431,6 +1420,23 @@ static int local_init(FsContext *ctx, Error **errp) break; } #endif + return 0; +} + +static int local_init(FsContext *ctx, Error **errp) +{ + LocalData *data = g_malloc(sizeof(*data)); + + data->mountfd = open(ctx->fs_root, O_DIRECTORY | O_RDONLY); + if (data->mountfd == -1) { + error_setg_errno(errp, errno, "failed to open '%s'", ctx->fs_root); + goto err; + } + + if (local_ioc_getversion_init(ctx, data, errp) < 0) { + close(data->mountfd); + goto err; + } if (ctx->export_flags & V9FS_SM_PASSTHROUGH) { ctx->xops = passthrough_xattr_ops; From patchwork Sat Jun 2 21:29:38 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Keno Fischer X-Patchwork-Id: 924604 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=juliacomputing.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=juliacomputing-com.20150623.gappssmtp.com header.i=@juliacomputing-com.20150623.gappssmtp.com header.b="awkqYjf+"; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 40yvXc5dSHz9s0W for ; Sun, 3 Jun 2018 07:31:44 +1000 (AEST) Received: from localhost ([::1]:32840 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fPE7i-0007yk-8z for incoming@patchwork.ozlabs.org; Sat, 02 Jun 2018 17:31:42 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44464) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fPE70-0007wf-1s for qemu-devel@nongnu.org; Sat, 02 Jun 2018 17:30:59 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fPE6z-0005oR-80 for qemu-devel@nongnu.org; Sat, 02 Jun 2018 17:30:58 -0400 Received: from mail-qt0-x242.google.com ([2607:f8b0:400d:c0d::242]:40146) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fPE6z-0005oF-2z for qemu-devel@nongnu.org; Sat, 02 Jun 2018 17:30:57 -0400 Received: by mail-qt0-x242.google.com with SMTP id q6-v6so2611723qtn.7 for ; Sat, 02 Jun 2018 14:30:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=juliacomputing-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=viO+UGj1DZ5PdNGzv9PR54c7TzmOc+Q8PpO4HHpL95w=; b=awkqYjf+XFOBsJ7rSu3DaYcXLYUQQG6IeTuxTvBzfIZKLG0lSoiQpAQdcSCpbTsR3v ExThxZ/rjlTRx1gW0yyXHPMYLQWM+hQGqsNiE6Kh23w8nIE8usl01llzwh6bo+cZBb+D 5eCQeRU1P9r41AG2Q8nTY33z1FbvK4h40GTTvSfsBMU8ElKlEShvWZD4rMNEiQLv/rPD +4LBk6wKZLy9u3TmPMb5kqquKgMtjrqjj3I7+MODzQWbnA2ZnASNRVnMrq5OKKp7SJOH GpeDvL4cS+tsHackSXA7bHTUT90RZWmQfNi/k3bIGpFwRqsSpaqtIHsYmCnNEcGqzJuR UEKA== 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:in-reply-to:references; bh=viO+UGj1DZ5PdNGzv9PR54c7TzmOc+Q8PpO4HHpL95w=; b=EQizMPXTYYACETyQ+u06vN3rvf+Z/m4QTEiuDvtUAAihRZMmS/9BjoNLRu/2xYCRac 5EzEHMjYrgw9DDWsyxddfQ0wkMzJUScWB7FWUnpSIttUwfIK01FUdN2Y9BfqUQf64L35 Tj6l2TfQtL5VXu6rmAWtZMYpP6BM8DCgmz9UPC4KSv7iF10EOV12Na+uEcBzF67mI7ln oZljNDigJTC8F9ZLFiGrD0L5ZKZT37he7LhAUnQLpmBZk9qLuqlGAeXF/pf9y4EAmZeU efc6Qh6wuwIukVvCwbSqP75Msx8JWHduM/f+x2SAZtghi36qNXkcQZHq35UPKp9a+Y78 uONA== X-Gm-Message-State: APt69E2Y07dMpxvk5kpXj/akkTyHo37ohSc1659ICiQXD2xkSRLvef3w NYkYVRI6B2tPwbDkb6aGvIPLbIn0yNY= X-Google-Smtp-Source: ADUXVKKBeuSWtdcrxw7x1e6STdlFj0XJNLA9GGgOTeqemttTKfGiA9aZnwspj2A59Hyu70jufh/Hvg== X-Received: by 2002:aed:35f0:: with SMTP id d45-v6mr15112710qte.92.1527975055950; Sat, 02 Jun 2018 14:30:55 -0700 (PDT) Received: from localhost.localdomain (96-86-104-61-static.hfc.comcastbusiness.net. [96.86.104.61]) by smtp.gmail.com with ESMTPSA id k2-v6sm21366628qkl.95.2018.06.02.14.30.54 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sat, 02 Jun 2018 14:30:54 -0700 (PDT) From: Keno Fischer To: qemu-devel@nongnu.org Date: Sat, 2 Jun 2018 17:29:38 -0400 Message-Id: <437736e77ecd0d5ecd6bb430319a6b0e2dfb571d.1527973524.git.keno@juliacomputing.com> X-Mailer: git-send-email 2.8.1 In-Reply-To: References: In-Reply-To: References: X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:400d:c0d::242 Subject: [Qemu-devel] [PATCH v3 4/5] 9p: Properly check/translate flags in unlinkat 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: Keno Fischer , groug@kaod.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" The 9p-local code previously relied on P9_DOTL_AT_REMOVEDIR and AT_REMOVEDIR having the same numerical value and deferred any errorchecking to the syscall itself. However, while the former assumption is true on Linux, it is not true in general. 9p-handle did this properly however. Move the translation code to the generic 9p server code and add an error if unrecognized flags are passed. Signed-off-by: Keno Fischer --- Changes since v2: * Remove 9p-handle code that did the same translation and is now incorrect. hw/9pfs/9p-handle.c | 8 +------- hw/9pfs/9p.c | 13 +++++++++++-- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/hw/9pfs/9p-handle.c b/hw/9pfs/9p-handle.c index 4dc0d2b..f3641db 100644 --- a/hw/9pfs/9p-handle.c +++ b/hw/9pfs/9p-handle.c @@ -559,19 +559,13 @@ static int handle_unlinkat(FsContext *ctx, V9fsPath *dir, { int dirfd, ret; HandleData *data = (HandleData *) ctx->private; - int rflags; dirfd = open_by_handle(data->mountfd, dir->data, O_PATH); if (dirfd < 0) { return dirfd; } - rflags = 0; - if (flags & P9_DOTL_AT_REMOVEDIR) { - rflags |= AT_REMOVEDIR; - } - - ret = unlinkat(dirfd, name, rflags); + ret = unlinkat(dirfd, name, flags); close(dirfd); return ret; diff --git a/hw/9pfs/9p.c b/hw/9pfs/9p.c index 4386d69..c842ec5 100644 --- a/hw/9pfs/9p.c +++ b/hw/9pfs/9p.c @@ -2522,7 +2522,7 @@ static void coroutine_fn v9fs_unlinkat(void *opaque) { int err = 0; V9fsString name; - int32_t dfid, flags; + int32_t dfid, flags, rflags = 0; size_t offset = 7; V9fsPath path; V9fsFidState *dfidp; @@ -2549,6 +2549,15 @@ static void coroutine_fn v9fs_unlinkat(void *opaque) goto out_nofid; } + if (flags & ~P9_DOTL_AT_REMOVEDIR) { + err = -EINVAL; + goto out_nofid; + } + + if (flags & P9_DOTL_AT_REMOVEDIR) { + rflags |= AT_REMOVEDIR; + } + dfidp = get_fid(pdu, dfid); if (dfidp == NULL) { err = -EINVAL; @@ -2567,7 +2576,7 @@ static void coroutine_fn v9fs_unlinkat(void *opaque) if (err < 0) { goto out_err; } - err = v9fs_co_unlinkat(pdu, &dfidp->path, &name, flags); + err = v9fs_co_unlinkat(pdu, &dfidp->path, &name, rflags); if (!err) { err = offset; } From patchwork Sat Jun 2 21:29:39 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Keno Fischer X-Patchwork-Id: 924606 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=juliacomputing.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=juliacomputing-com.20150623.gappssmtp.com header.i=@juliacomputing-com.20150623.gappssmtp.com header.b="ZBI0+K8V"; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 40yvZ72kpwz9s0W for ; Sun, 3 Jun 2018 07:33:03 +1000 (AEST) Received: from localhost ([::1]:32843 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fPE8y-0000aO-V5 for incoming@patchwork.ozlabs.org; Sat, 02 Jun 2018 17:33:00 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44475) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fPE71-0007xr-Kl for qemu-devel@nongnu.org; Sat, 02 Jun 2018 17:31:00 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fPE70-0005pQ-M6 for qemu-devel@nongnu.org; Sat, 02 Jun 2018 17:30:59 -0400 Received: from mail-qt0-x244.google.com ([2607:f8b0:400d:c0d::244]:40148) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fPE70-0005pG-Hb for qemu-devel@nongnu.org; Sat, 02 Jun 2018 17:30:58 -0400 Received: by mail-qt0-x244.google.com with SMTP id q6-v6so2611766qtn.7 for ; Sat, 02 Jun 2018 14:30:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=juliacomputing-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=2lVGDeuS5rQOtCR6f/x1d+TXu6O90X6nTjdRqW5XFC4=; b=ZBI0+K8Ve/L6JA0gLL8FCFNOlppdJGYYPZY/3GDziC+gBHdXRzOBDKmi2VCkUBG/bK 7nSfnT/uKfyM4Yr+6BF2f/TIu077YVq/khkTyn18HglHgPcXz/zBFSO+Rnqgv7oeJybm 3iOC2VP3NOem3ZjW21yNoMOP3fwFT2Wo84dDJqdwRZWI8yrzx3eWyn906F3SmhJRHtcz Sl200PI5TFBWSBIHKa1QBOtQmc+245NL61ontdsnVEo/mvtjgKL+HPeMutC/cjGydO1Q 796pmvRkEtylqgyc37SwLBKbqbpeEs0Z7Irm//8JGZVDorSbJFlviaLA5to5sRnuBKqz uejQ== 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:in-reply-to:references; bh=2lVGDeuS5rQOtCR6f/x1d+TXu6O90X6nTjdRqW5XFC4=; b=cMXTf8rPnzw2L+WyehUNxJKJzC7E/fI36XexqS3Wyp/TJHZbHSjTak1osJwTdCV50e cwnNirJUvHkJi9oIL3OK7RvHRAYkoZCHNv/iIzrAaUWJ8ulFXVfMtDSxwQO29Py2MS8+ nWkmHsedOapIHM/eMtAs2Xm3SGYUCCEchvs6Pm/pdM3rPKrjJc3KaD/xubZU3iCZwrwe rAGceUOa8ezjb0XI/DNPIq6Zw7/1rZQnNpV2cIF0CDScD1iFg5j3uBKOlcZHSg0yhwlb NSWrOcdx2/PW1+FnytqFx7L7ZVXFTfO/lDmCJ/cvS9l+CNrlDzLBwL/y4WxS5rAKdG2b 97Dg== X-Gm-Message-State: APt69E3diylkgJh8oetBt7R94JRhr/jRPDFVRrhvEunXYhQaBXo3eS2P csaMrkD54fXblVlodTuWJSvFMKQz/LI= X-Google-Smtp-Source: ADUXVKL0afCFzfzqrfUUcO33QO/5mFACy09Aj6akb0Q9Byhb4yULu7SLCjuQR8m8rOqsxdfpo6U1+g== X-Received: by 2002:ac8:2d6c:: with SMTP id o41-v6mr15723923qta.107.1527975057449; Sat, 02 Jun 2018 14:30:57 -0700 (PDT) Received: from localhost.localdomain (96-86-104-61-static.hfc.comcastbusiness.net. [96.86.104.61]) by smtp.gmail.com with ESMTPSA id k2-v6sm21366628qkl.95.2018.06.02.14.30.55 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sat, 02 Jun 2018 14:30:56 -0700 (PDT) From: Keno Fischer To: qemu-devel@nongnu.org Date: Sat, 2 Jun 2018 17:29:39 -0400 Message-Id: X-Mailer: git-send-email 2.8.1 In-Reply-To: References: In-Reply-To: References: X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:400d:c0d::244 Subject: [Qemu-devel] [PATCH v3 5/5] 9p: xattr: Properly translate xattrcreate flags 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: Keno Fischer , groug@kaod.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" As with unlinkat, these flags come from the client and need to be translated to their host values. The protocol values happen to match linux, but that need not be true in general. Signed-off-by: Keno Fischer --- Changes since v2: New patch hw/9pfs/9p.c | 17 +++++++++++++++-- hw/9pfs/9p.h | 4 ++++ 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/hw/9pfs/9p.c b/hw/9pfs/9p.c index c842ec5..eef289e 100644 --- a/hw/9pfs/9p.c +++ b/hw/9pfs/9p.c @@ -3327,7 +3327,7 @@ out_nofid: static void coroutine_fn v9fs_xattrcreate(void *opaque) { - int flags; + int flags, rflags = 0; int32_t fid; uint64_t size; ssize_t err = 0; @@ -3344,6 +3344,19 @@ static void coroutine_fn v9fs_xattrcreate(void *opaque) } trace_v9fs_xattrcreate(pdu->tag, pdu->id, fid, name.data, size, flags); + if (flags & ~(P9_XATTR_CREATE | P9_XATTR_REPLACE)) { + err = -EINVAL; + goto out_nofid; + } + + if (flags & P9_XATTR_CREATE) { + rflags |= XATTR_CREATE; + } + + if (flags & P9_XATTR_REPLACE) { + rflags |= XATTR_REPLACE; + } + if (size > XATTR_SIZE_MAX) { err = -E2BIG; goto out_nofid; @@ -3365,7 +3378,7 @@ static void coroutine_fn v9fs_xattrcreate(void *opaque) xattr_fidp->fs.xattr.copied_len = 0; xattr_fidp->fs.xattr.xattrwalk_fid = false; xattr_fidp->fs.xattr.len = size; - xattr_fidp->fs.xattr.flags = flags; + xattr_fidp->fs.xattr.flags = rflags; v9fs_string_init(&xattr_fidp->fs.xattr.name); v9fs_string_copy(&xattr_fidp->fs.xattr.name, &name); xattr_fidp->fs.xattr.value = g_malloc0(size); diff --git a/hw/9pfs/9p.h b/hw/9pfs/9p.h index bad8ee7..6081b0d 100644 --- a/hw/9pfs/9p.h +++ b/hw/9pfs/9p.h @@ -169,6 +169,10 @@ typedef struct V9fsConf char *fsdev_id; } V9fsConf; +/* 9p2000.L xattr flags (matches Linux values) */ +#define P9_XATTR_CREATE 1 +#define P9_XATTR_REPLACE 2 + typedef struct V9fsXattr { uint64_t copied_len;