Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp271228imm; Thu, 2 Aug 2018 18:47:43 -0700 (PDT) X-Google-Smtp-Source: AAOMgpf7wyjd0A2dLDtrviR4dD3la0uYYb9NPlTliJZzbcaFNGsWXC2atrIkUJ1vq9tp0lqRcbAX X-Received: by 2002:a62:3f55:: with SMTP id m82-v6mr2061834pfa.51.1533260863457; Thu, 02 Aug 2018 18:47:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1533260863; cv=none; d=google.com; s=arc-20160816; b=KbV32doFiehMirXq/JRvfhp2G3Hdw9vL2qTrhH/wxTJIaqhFLbErMQAUNBf6Y252Of QDPzAx8CptpulQjSeSnur7deA+GZDeGXN4MBiRNZcXf5ONFHlNLw8jF0nyIj+zhZUAh6 lm/0zHJnysbGgJlEji7c5b64IxWbjhyacwVS5zSTSdWueoc1eMOPPYEPULTFeSaL8B9t vIPywv4EHWoQYBB4risqy7byjlsTT/rAL2ROxarBOUn1RjxWhTVFPs4ZPiAjIpYro2uz vJpc5juB1ys2YBJIDFNgrS9iF/VP91WMpu/ZFTdkW1BZBNNKBbjneWp/IRxKotI9kxql PmSQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:in-reply-to :mime-version:user-agent:date:message-id:from:cc:references:to :subject:arc-authentication-results; bh=w001y5s0/YiyArvuLGKJYMWMWUmrSpdtVVQcZJrAW6Y=; b=FJBwxLFchkPqRCzqF13aZGyoPraTUtasqEyo/jY4VbxojgUT+q5GMZuGcgNaT38RVl zfjYpMkuwbPOLaKAq74lwt6RdnTDXi+h0CakQLT6JtrEj8tX1t+PwSPy2ObyK9bB9EbX r1pahozVi1Yjloe817cIpB9DZ49P5WwnRmvYI1a0JV0qCL5wVNGvezdCm8vw9i7YX50X PfL9hP8ZfP7X9v8gYkw3b8b/xMlxJmtWLLQvbIEDOLXrezM22bHHSQTSGt8QBYOXZEEz RcwzI+aquKw3PwiOAfGicvYgg713Hm93KSrSNPXwelQP6J4S6e0aEjNST7hOO/LJFGHA qnTw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d1-v6si2872875pgo.337.2018.08.02.18.47.28; Thu, 02 Aug 2018 18:47:43 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732331AbeHCDkI (ORCPT + 99 others); Thu, 2 Aug 2018 23:40:08 -0400 Received: from szxga04-in.huawei.com ([45.249.212.190]:10615 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1729765AbeHCDkI (ORCPT ); Thu, 2 Aug 2018 23:40:08 -0400 Received: from DGGEMS413-HUB.china.huawei.com (unknown [172.30.72.59]) by Forcepoint Email with ESMTP id 9740B22FC7C56; Fri, 3 Aug 2018 09:46:14 +0800 (CST) Received: from [10.177.253.249] (10.177.253.249) by smtp.huawei.com (10.3.19.213) with Microsoft SMTP Server id 14.3.399.0; Fri, 3 Aug 2018 09:46:14 +0800 Subject: Re: [V9fs-developer] [PATCH v2] net/9p/trans_virtio.c: add null terminal for mount tag To: Greg Kurz References: <5B6262F4.9080601@huawei.com> <20180802015439.GA27403@nautica> <5B62658A.3010605@huawei.com> <20180802152339.194c2820@bahia.lan> CC: Dominique Martinet , Latchesar Ionkov , Eric Van Hensbergen , "Linux Kernel Mailing List" , , Ron Minnich From: piaojun Message-ID: <5B63B3CE.3040601@huawei.com> Date: Fri, 3 Aug 2018 09:45:50 +0800 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:38.0) Gecko/20100101 Thunderbird/38.2.0 MIME-Version: 1.0 In-Reply-To: <20180802152339.194c2820@bahia.lan> Content-Type: text/plain; charset="windows-1252" Content-Transfer-Encoding: 7bit X-Originating-IP: [10.177.253.249] X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Greg and Dominique, We'd better reach an agreement about the patch fix. In my opinion, replacing strlen(chan->tag) with a local variable sounds reasonable, and changing strncmp to strcmp may be little beneficial, as strcmp is more dangerours such as buffer-flow. So I'd like to hear your suggestion for the next version of the patch, or this patch is good enough? Thanks, Jun On 2018/8/2 21:23, Greg Kurz wrote: > On Thu, 2 Aug 2018 09:59:38 +0800 > piaojun wrote: > >> Hi Dominique, >> >> On 2018/8/2 9:54, Dominique Martinet wrote: >>> piaojun wrote on Thu, Aug 02, 2018: >>>> chan->tag is Non-null terminated which will result in printing messy code >>>> when debugging code. So we should add '\0' for tag to make the code more >>>> convenient and robust. In addition, I drop char->tag_len to simplify the >>>> code. >>> >>> Some new lines in commit message would be appreciated. >>> >>> That aside, I have a couple of nitpicks, but it looks good to me - thanks >>> >>>> >>>> Signed-off-by: Jun Piao >>>> --- >>>> net/9p/trans_virtio.c | 15 +++++---------- >>>> 1 file changed, 5 insertions(+), 10 deletions(-) >>>> >>>> diff --git a/net/9p/trans_virtio.c b/net/9p/trans_virtio.c >>>> index d422bfc..0fe9c37 100644 >>>> --- a/net/9p/trans_virtio.c >>>> +++ b/net/9p/trans_virtio.c >>>> @@ -89,10 +89,8 @@ struct virtio_chan { >>>> unsigned long p9_max_pages; >>>> /* Scatterlist: can be too big for stack. */ >>>> struct scatterlist sg[VIRTQUEUE_NUM]; >>>> - >>>> - int tag_len; >>>> /* >>>> - * tag name to identify a mount Non-null terminated >>>> + * tag name to identify a mount null terminated >>>> */ >>>> char *tag; >>>> >>>> @@ -529,10 +527,9 @@ static ssize_t p9_mount_tag_show(struct device *dev, >>>> vdev = dev_to_virtio(dev); >>>> chan = vdev->priv; >>>> >>>> - memcpy(buf, chan->tag, chan->tag_len); >>>> - buf[chan->tag_len] = 0; >>>> + memcpy(buf, chan->tag, strlen(chan->tag) + 1); >>>> >>>> - return chan->tag_len + 1; >>>> + return strlen(chan->tag) + 1; >>> >>> Use a local variable for strlen(chan->tag)? >>> >> Yes, local variable looks better. >> >>>> } >>>> >>>> static DEVICE_ATTR(mount_tag, 0444, p9_mount_tag_show, NULL); >>>> @@ -585,7 +582,7 @@ static int p9_virtio_probe(struct virtio_device *vdev) >>>> err = -EINVAL; >>>> goto out_free_vq; >>>> } >>>> - tag = kmalloc(tag_len, GFP_KERNEL); >>>> + tag = kzalloc(tag_len + 1, GFP_KERNEL); >>>> if (!tag) { >>>> err = -ENOMEM; >>>> goto out_free_vq; >>>> @@ -594,7 +591,6 @@ static int p9_virtio_probe(struct virtio_device *vdev) >>>> virtio_cread_bytes(vdev, offsetof(struct virtio_9p_config, tag), >>>> tag, tag_len); >>>> chan->tag = tag; >>>> - chan->tag_len = tag_len; >>>> err = sysfs_create_file(&(vdev->dev.kobj), &dev_attr_mount_tag.attr); >>>> if (err) { >>>> goto out_free_tag; >>>> @@ -654,8 +650,7 @@ static int p9_virtio_probe(struct virtio_device *vdev) >>>> >>>> mutex_lock(&virtio_9p_lock); >>>> list_for_each_entry(chan, &virtio_chan_list, chan_list) { >>>> - if (!strncmp(devname, chan->tag, chan->tag_len) && >>>> - strlen(devname) == chan->tag_len) { >>>> + if (!strncmp(devname, chan->tag, strlen(chan->tag) + 1)) { >>> >>> strncmp(x, y, strlen(y)+1) is precisely what strcmp does so let's use >>> the simpler version >>> >> strcmp looks simpler, and I will wait for a while to hear more >> suggestions, and then post another patch for these fixes. >> > > Nothing more to add. Please go ahead. > >> Thanks, >> Jun >> >> ------------------------------------------------------------------------------ >> Check out the vibrant tech community on one of the world's most >> engaging tech sites, Slashdot.org! http://sdm.link/slashdot >> _______________________________________________ >> V9fs-developer mailing list >> V9fs-developer@lists.sourceforge.net >> https://lists.sourceforge.net/lists/listinfo/v9fs-developer > > . >