From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.3 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3ED41C43331 for ; Fri, 3 Apr 2020 15:33:55 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 1924E20721 for ; Fri, 3 Apr 2020 15:33:55 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 1924E20721 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=suse.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1jKOKH-0003nU-7P; Fri, 03 Apr 2020 15:33:45 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1jKOKF-0003nP-S7 for xen-devel@lists.xenproject.org; Fri, 03 Apr 2020 15:33:43 +0000 X-Inumbo-ID: 7fcba542-75c0-11ea-bd3a-12813bfff9fa Received: from mx2.suse.de (unknown [195.135.220.15]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 7fcba542-75c0-11ea-bd3a-12813bfff9fa; Fri, 03 Apr 2020 15:33:43 +0000 (UTC) X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id E86E5ABEF; Fri, 3 Apr 2020 15:33:41 +0000 (UTC) Subject: Re: [PATCH v7 04/12] xen: add basic hypervisor filesystem support To: Jan Beulich References: <20200402154616.16927-1-jgross@suse.com> <20200402154616.16927-5-jgross@suse.com> <7dda5c2c-cb81-2cfa-2cf4-4440b49d401a@suse.com> <1b83570b-17ac-9da4-cfee-fbd44c7d3edf@suse.com> From: =?UTF-8?B?SsO8cmdlbiBHcm/Dnw==?= Message-ID: <2a38a209-de27-1b83-8034-07f6510739e5@suse.com> Date: Fri, 3 Apr 2020 17:33:41 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.6.0 MIME-Version: 1.0 In-Reply-To: <1b83570b-17ac-9da4-cfee-fbd44c7d3edf@suse.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Stefano Stabellini , Julien Grall , Wei Liu , Andrew Cooper , Ian Jackson , George Dunlap , xen-devel@lists.xenproject.org, Daniel De Graaf , Volodymyr Babchuk , =?UTF-8?Q?Roger_Pau_Monn=c3=a9?= Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" On 03.04.20 17:31, Jan Beulich wrote: > On 03.04.2020 17:05, Jürgen Groß wrote: >> On 03.04.20 16:23, Jan Beulich wrote: >>> On 02.04.2020 17:46, Juergen Gross wrote: >>>> +int hypfs_write_leaf(struct hypfs_entry_leaf *leaf, >>>> +                     XEN_GUEST_HANDLE_PARAM(void) uaddr, unsigned long ulen) >>>> +{ >>>> +    char *buf; >>>> +    int ret; >>>> + >>>> +    if ( leaf->e.type != XEN_HYPFS_TYPE_STRING && >>>> +         leaf->e.type != XEN_HYPFS_TYPE_BLOB && ulen != leaf->e.size ) >>>> +        return -EDOM; >>>> + >>>> +    buf = xmalloc_array(char, ulen); >>>> +    if ( !buf ) >>>> +        return -ENOMEM; >>>> + >>>> +    ret = -EFAULT; >>>> +    if ( copy_from_guest(buf, uaddr, ulen) ) >>>> +        goto out; >>>> + >>>> +    ret = -EINVAL; >>>> +    if ( leaf->e.type == XEN_HYPFS_TYPE_STRING && >>>> +         memchr(buf, 0, ulen) != (buf + ulen - 1) ) >>>> +        goto out; >>>> + >>>> +    ret = 0; >>>> +    memcpy(leaf->write_ptr, buf, ulen); >>>> +    leaf->e.size = ulen; >>>> + >>>> + out: >>>> +    xfree(buf); >>>> +    return ret; >>>> +} >>>> + >>>> +int hypfs_write_bool(struct hypfs_entry_leaf *leaf, >>>> +                     XEN_GUEST_HANDLE_PARAM(void) uaddr, unsigned long ulen) >>>> +{ >>>> +    bool buf; >>>> + >>>> +    ASSERT(leaf->e.type == XEN_HYPFS_TYPE_BOOL && leaf->e.size == sizeof(bool)); >>>> + >>>> +    if ( ulen != leaf->e.max_size ) >>> >>> Why max_size here when the ASSERT() checks size? >> >> Just for consistency with the other write functions. > > In which case perhaps extend the ASSERT() to also check max_size? Okay. > >>>> +static int hypfs_write(struct hypfs_entry *entry, >>>> +                       XEN_GUEST_HANDLE_PARAM(void) uaddr, unsigned long ulen) >>>> +{ >>>> +    struct hypfs_entry_leaf *l; >>>> + >>>> +    if ( !entry->write ) >>>> +        return -EACCES; >>>> + >>>> +    if ( ulen > entry->max_size ) >>>> +        return -ENOSPC; >>> >>> max_size being zero for non-writable entries, perhaps use -EACCES >>> also for this special case? Together with the other comment above, >>> maybe the ->write check wants replacing this way? >> >> Checking the write function being not NULL is a nice security addon, >> as I avoid to call into a non existing function. Basically both tests >> would be equivalent, but this one is IMO better to avoid crashes. > > In which case perhaps ASSERT(entry->max_size) between the two if()s? Okay. Juergen