From owner-svn-src-all@freebsd.org Thu Aug 16 23:23:28 2018 Return-Path: Delivered-To: svn-src-all@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id E70ED1079D86 for ; Thu, 16 Aug 2018 23:23:27 +0000 (UTC) (envelope-from wlosh@bsdimp.com) Received: from mail-it0-x22d.google.com (mail-it0-x22d.google.com [IPv6:2607:f8b0:4001:c0b::22d]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client CN "smtp.gmail.com", Issuer "Google Internet Authority G3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 747597DDFB for ; Thu, 16 Aug 2018 23:23:27 +0000 (UTC) (envelope-from wlosh@bsdimp.com) Received: by mail-it0-x22d.google.com with SMTP id v71-v6so9195380itb.3 for ; Thu, 16 Aug 2018 16:23:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20150623.gappssmtp.com; s=20150623; h=mime-version:sender:in-reply-to:references:from:date:message-id :subject:to:cc; bh=xWlSBvuhuYVbERPhigAxUXseugL1Gy8t1I9A/IqZChc=; b=Ig5FQp4nm12MN6Hk509QSgKN72fFLDcHC25C3LodiJn88GUeXI11AgTlCgI4Ow196J +EgKL+UvhjhyurMb5w+V0IXRIufPXNKhO6qsZRH5Omq8r97eBn9GNgMuozJPsVYeqRKT +Y0MuOjNxUP7M0r2/2HuOgc6tlO7UNKCx9HNK1IpMig9hrHZ12RVd7vpu9EwFV/v7asI sPKt2OI8mPQRN/nMRMujEpLUmKlK3B1pxvxDwwPXIctiwYYhBmuN7UtdM7KGlmknYdSP rfnHGLcIV1U9dcub1Yj1jpz29fPO5mljpSuTwLJVl2DWB9AEQWl9UFO5etPRPf6ZX4c1 jBxg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:sender:in-reply-to:references:from :date:message-id:subject:to:cc; bh=xWlSBvuhuYVbERPhigAxUXseugL1Gy8t1I9A/IqZChc=; b=e5Jp0UuhFuUJmBmCijan3RdoaSRzt6XO6WM9S5dQFuWla8Uvzdm5KYKWVponvQdoj3 6CY+uZUIyu+aYXLUIX9ExjxQTvyyzAD7lONh/CcE9O4ptzTQrD4oWPYLTB8+/sueZt4j pvqDbFRF8Zte+VrWGH8VrUKZ15uh7ZwvNsJ4p2ucTvQmk+b/UWIeTa0+p0rUZ75/jjfO 5eOfiP5V/l5GgFm570NxCLTIkErUlxduf8qHKGR74ABpihdZz+j7Uj8aOxwDDEAZUBWL OEVTi8tzxAAWU/zn1YySMIseZU4DP798vXOlyMdT9RcWjPXipAvsna//zEG+y7/lOa3D vM1Q== X-Gm-Message-State: AOUpUlGSEhxpGOWIrvqzbL3+cDJz6whTFOR34xL7xU9GbQ7ROkdYXIej rCOhUjAqpuFel44tQomRBFsAPyDawT2zjizbqv0Byg== X-Google-Smtp-Source: AA+uWPwiEZd5jhebxBXiEeY5zUfAJG4QusB/mvgDkIFanrgZGGA55OSW5XpGP8n1QJfMIGjZ4O+QMhjRayYu6QeoNII= X-Received: by 2002:a02:bb04:: with SMTP id y4-v6mr29359414jan.5.1534461806685; Thu, 16 Aug 2018 16:23:26 -0700 (PDT) MIME-Version: 1.0 Sender: wlosh@bsdimp.com Received: by 2002:a4f:257:0:0:0:0:0 with HTTP; Thu, 16 Aug 2018 16:23:26 -0700 (PDT) X-Originating-IP: [2603:300b:6:5100:1052:acc7:f9de:2b6d] In-Reply-To: <20180816231630.GA10866@spindle.one-eyed-alien.net> References: <201808161929.w7GJTWfS055411@pdx.rh.CN85.dnsmgr.net> <20180816231630.GA10866@spindle.one-eyed-alien.net> From: Warner Losh Date: Thu, 16 Aug 2018 17:23:26 -0600 X-Google-Sender-Auth: olueA3Rb9hxvz_rUaErv-qwi-Tk Message-ID: Subject: Re: svn commit: r337887 - head/usr.sbin/bhyve To: Brooks Davis Cc: Marcelo Araujo , "Rodney W. Grimes" , John-Mark Gurney , src-committers , svn-src-all@freebsd.org, svn-src-head@freebsd.org Content-Type: text/plain; charset="UTF-8" X-Content-Filtered-By: Mailman/MimeDel 2.1.27 X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.27 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 16 Aug 2018 23:23:28 -0000 On Thu, Aug 16, 2018 at 5:16 PM, Brooks Davis wrote: > On Fri, Aug 17, 2018 at 07:04:05AM +0800, Marcelo Araujo wrote: > > 2018-08-17 3:29 GMT+08:00 Rodney W. Grimes net>: > > > > > > On Thu, Aug 16, 2018 at 11:06 AM, John-Mark Gurney > > > > wrote: > > > > > > > > > Marcelo Araujo wrote this message on Thu, Aug 16, 2018 at 06:31 > +0000: > > > > > > Author: araujo > > > > > > Date: Thu Aug 16 06:31:54 2018 > > > > > > New Revision: 337887 > > > > > > URL: https://svnweb.freebsd.org/changeset/base/337887 > > > > > > > > > > > > Log: > > > > > > Add a comment explaining how the PSN works and why there is no > > > need for > > > > > > a null terminator. Also mark CID 1394825 as intentional. > > > > > > > > > > > > Reported by: Coverity > > > > > > CID: 1394825 > > > > > > MFC after: 1 week > > > > > > Sponsored by: iXsystems Inc. > > > > > > > > > > > > Modified: > > > > > > head/usr.sbin/bhyve/pci_nvme.c > > > > > > > > > > > > Modified: head/usr.sbin/bhyve/pci_nvme.c > > > > > > ============================================================ > > > > > ================== > > > > > > --- head/usr.sbin/bhyve/pci_nvme.c Thu Aug 16 06:20:25 2018 > > > > > (r337886) > > > > > > +++ head/usr.sbin/bhyve/pci_nvme.c Thu Aug 16 06:31:54 2018 > > > > > (r337887) > > > > > > @@ -1714,6 +1714,11 @@ pci_nvme_parse_opts(struct pci_nvme_softc > *sc, > > > > > char *o > > > > > > > > > > [...] > > > > > > > > > > > memset(sc->ctrldata.sn, 0, sizeof(sc-> > > > ctrldata.sn > > > > > )); > > > > > > strncpy(sc->ctrldata.sn, config, > > > > > > sizeof(sc->ctrldata.sn)); > > > > > > > > > > This memset is unneeded, as strncpy will write NUL bytes to fill > out > > > > > the buffer: > > > > > If src is less than len characters long, the remainder of > > > > > dst is filled with `\0' characters. > > > > > > > > > > > > > It also looks like the comment was wrong. The newest NVMe standards > say > > > > these fields should be 7-bit and space-padded. > > > > > > lol, which is what the vendor that caused me grief with > > > ata serial numbers did decades ago. > > > > > > -- > > > Rod Grimes > > > rgrimes@freebsd.org > > > > > > > I have discussed a bit with imp@, but I will drop the patch here to get > > other peoples opinion too. > > So, name space and firmware number also need to be padded with spaces. > > > > I couldn't think in any other better way to do that. > > > > Does this patch looks reasonable? > > https://people.freebsd.org/~araujo/pci_nvme.diff > > You should check that len<=dst_size and at least truncate rather than > overflowing. If the strings from userspace you need to return or log an > error, if they come from the kernel, you can panic. > Help me understand, I thought that the strnlen bounded what was copied. Warner