Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp284398imm; Thu, 2 Aug 2018 19:07:32 -0700 (PDT) X-Google-Smtp-Source: AAOMgpcN84fYOFqDd4CrdpMcsPHzSX69eFYcmWEThtyPbTWzpcN3Y730SijoYdCun3wqScO4uBn8 X-Received: by 2002:a17:902:aa46:: with SMTP id c6-v6mr1626790plr.313.1533262051995; Thu, 02 Aug 2018 19:07:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1533262051; cv=none; d=google.com; s=arc-20160816; b=uW+ujTFnI3QGj7Nrng5gz9VDFTzWUAUwjP4Wh26I/uSGnhbtpKH/vBTGwjBzP+P+I4 0Zcdg2t1e4E9gvOiULPwFPpuQFQenNOzasVes8rmtSN0ouySC8JgcV8ETfFjxlMjiCAa Q2+oYd1xOr2elwi115ey/8Ut2Ye5MDx3CPfSDvJknKMzSnxUxSdh+J3v91ulqxDtB+3x mEPbZJi73Ucs6LT1P3o2lxVk8skiTjTzUazV50iJnzWN4n3aE0xW1WjNGTYLHLFXSlG3 GIAuj89+d48V4aeaOJFBfq95xQgUyCoM0qd/SKpBMsMEoC6yy0DkPbNRBCMUSpw8EGkp 7GNQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:arc-authentication-results; bh=s5habxRQ0IovkvQfsK9z7Gdr1rA5Cof+NmV3aHNw030=; b=ULNR3tDW00hXkJnVd+EUIKyJ0Mp21Ddtz9QU8QelI9j6WWv0Rv/SqGo/Vn7sMjY9zM /ZWKQzHoC8BBviz5Qx7ZlIGIm6NFhmZgM9nj0Z4eC6LCSsrrGqxLFd3NcXPgVPqZncpS rOoKeZZzbFihyh+adkUQ8fANLYdiyIP4I4RP07osbOzDtvwTsbWYBlD5dV6W+m5y5Gsa 9V7P5dK4we19HaZX+SXSx6cOfoA/xMfANk3P5/nWiGQtR+/zduQdHx+2FTVf5NalJt0f v06SMBT7W5Hr4OUw84XO1JooRdno55vs940wuJSCTHrsDcIugfYDQasuTrFwx5LX7jI1 eJ9A== 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 y123-v6si3865245pfc.302.2018.08.02.19.07.16; Thu, 02 Aug 2018 19:07:31 -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 S1726104AbeHCEAW (ORCPT + 99 others); Fri, 3 Aug 2018 00:00:22 -0400 Received: from nautica.notk.org ([91.121.71.147]:58896 "EHLO nautica.notk.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725731AbeHCEAW (ORCPT ); Fri, 3 Aug 2018 00:00:22 -0400 Received: by nautica.notk.org (Postfix, from userid 1001) id 70159C009; Fri, 3 Aug 2018 04:06:23 +0200 (CEST) Date: Fri, 3 Aug 2018 04:06:08 +0200 From: Dominique Martinet To: piaojun Cc: Greg Kurz , Latchesar Ionkov , Eric Van Hensbergen , Linux Kernel Mailing List , v9fs-developer@lists.sourceforge.net, Ron Minnich Subject: Re: [V9fs-developer] [PATCH v2] net/9p/trans_virtio.c: add null terminal for mount tag Message-ID: <20180803020608.GA15635@nautica> References: <5B6262F4.9080601@huawei.com> <20180802015439.GA27403@nautica> <5B62658A.3010605@huawei.com> <20180802152339.194c2820@bahia.lan> <5B63B3CE.3040601@huawei.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <5B63B3CE.3040601@huawei.com> User-Agent: Mutt/1.5.21 (2010-09-15) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org piaojun wrote on Fri, Aug 03, 2018: > We'd better reach an agreement about the patch fix. The way I read Greg's comment was that he agreed to the proposed changes and is waiting for a new version. I'm writing a longer reply than I should because I don't like people saying strncmp is safe just because it's strncmp, feel free to skim through the rest as it's just ranting. > In my opinion, replacing strlen(chan->tag) with a local variable > sounds reasonable, So we agree here > and changing strncmp to strcmp may be little beneficial, as strcmp is more > dangerours such as buffer-flow. strcmp is more dangerous for buffer-overflow if you're comparing "unsafe" non-null terminated strings. This isn't the case here as you've constructed chan->tag yourself and you rely on it being null-terminated by calling strlen() on it yourself. strncmp(x, y, strlen(y)+1) is at best awkward, but it's a false sense of security if you think this is any better than strcmp here. It implies that: - y is null-terminated (for strlen() to work) - x is either null-terminated or longer than y Here, x is the devname argument to p9_virtio_create, which comes straight from the mount syscall with "copy_mount_string", using strndup_user, which returns a null-terminated string or an error. (the code is currently not safe if it returns an error, I'm sending another mail about it right after this one as we already have a partial fix) strcmp(x, y) on the other hand assumes that x and y are null-terminated in this case, which is the same assumptions you have, so is strictly as "safe" as strncmp used that way. (it could also assume that one is null terminated and the other one is at least as long as that, e.g. when comparing a "char buf[42]" to the constant "foo" then we don't care if buf is null-terminated) Thanks, -- Dominique