From owner-svn-src-head@freebsd.org Fri Aug 17 00:51:24 2018 Return-Path: Delivered-To: svn-src-head@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 BD323107C663; Fri, 17 Aug 2018 00:51:23 +0000 (UTC) (envelope-from araujobsdport@gmail.com) Received: from mail-lf1-x132.google.com (mail-lf1-x132.google.com [IPv6:2a00:1450:4864:20::132]) (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 3416E8260A; Fri, 17 Aug 2018 00:51:23 +0000 (UTC) (envelope-from araujobsdport@gmail.com) Received: by mail-lf1-x132.google.com with SMTP id f135-v6so4708437lfg.10; Thu, 16 Aug 2018 17:51:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:reply-to:in-reply-to:references:from:date:message-id :subject:to:cc; bh=A2ln+Con41RP9XWOJyUw636exI8bbkmFE6IaROOZBxk=; b=BhmUel0S9RigOq4t37x1bZvi+TW4RV3cDBUkYgOp4mb0cM8C8Lrx96uqhzZfXLdtYI 71hrlANOulCFYJqnvkrtfxTB5H26TEPuYo9VYlfvclyTPDa9H6URrsicV8qCBv6NJAoJ xsKlx4e16PLLAVNcDN2mkJU8U2kyyThf3lIGmGHICIjffABAoMUp49xTldddR7UhgTIO ZmfTMkQGV5XKJyb/j+E764eFjyTv/PIaguGnOCdbOZYsa+235CwXXEiovNrh1ShW8F90 c4S/kVRh7gaPW0g04tJC8K0dJvyBjCIkDx7dvikYx7JDBMVg8ph3xc8oVaRQ/bvEvMZE 2yKw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:reply-to:in-reply-to:references :from:date:message-id:subject:to:cc; bh=A2ln+Con41RP9XWOJyUw636exI8bbkmFE6IaROOZBxk=; b=tCZSvtyUXCSsP44a20QaknqhxRBM4ogu30LyZIBqBA+FZdpuYv+2Lu4ki+hlrWNvm0 GmRk0fQ4KNPVZNIQqEefIPe/sX4/NSS91yZDeFoUFLV+mvFLZXs5dNsUUZKCCMhD9Acu momLvagmV8MAw0vr55PHmb+3S8OS8rBUGp3HjTD6a8A4Gw3EyEdTTDrRexlWMtwMuCNV LAZAX5MvI0t42oyrY1IeQyxaLLUwHln22OvfnVVjDvY6UOq8pj1Jb2+ANgjOYeSzWcRF gMZKn6JIqnMuNOxJXcIgWjbZFgcUVaKjhfxWcii/8hsB9VRmbyARwTta5/dQZ7IoyxTz fZ2w== X-Gm-Message-State: AOUpUlEsdOczxLMf81YQSM1zOTer6QKL5zx90vqEGoEGqhTG+Am0sWcO dfnPbb9fjerOCAWTKsadrgpo5YJ7bEIqai+wgUEQaaUd X-Google-Smtp-Source: AA+uWPziHfN75vpG9syvP3OznVdX04YpExbGgHdU0yiSFxqVtb29xGaFNbwl7dqiVNNS8AlGTyQ4gVbO5QpxmTFxjls= X-Received: by 2002:a19:9710:: with SMTP id z16-v6mr21748875lfd.17.1534467081491; Thu, 16 Aug 2018 17:51:21 -0700 (PDT) MIME-Version: 1.0 Received: by 2002:a19:1f4c:0:0:0:0:0 with HTTP; Thu, 16 Aug 2018 17:51:20 -0700 (PDT) Reply-To: araujo@freebsd.org In-Reply-To: <20180816233314.GA11357@spindle.one-eyed-alien.net> References: <201808161929.w7GJTWfS055411@pdx.rh.CN85.dnsmgr.net> <20180816231630.GA10866@spindle.one-eyed-alien.net> <20180816233314.GA11357@spindle.one-eyed-alien.net> From: Marcelo Araujo Date: Fri, 17 Aug 2018 08:51:20 +0800 Message-ID: Subject: Re: svn commit: r337887 - head/usr.sbin/bhyve To: Brooks Davis Cc: Warner Losh , "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-head@freebsd.org X-Mailman-Version: 2.1.27 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 17 Aug 2018 00:51:24 -0000 2018-08-17 7:33 GMT+08:00 Brooks Davis : > On Thu, Aug 16, 2018 at 05:23:26PM -0600, Warner Losh wrote: > > 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 < > jmg@funkthat.com > > > > > > > > > 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. > > Apparently the standard calls for ' ' rather than '\0' padding. The > prop memcpy+memset does the job, but contains potential overflows. > > -- Brooks > Maybe I missed something, but when I call cpywithpad() I pass the dst_size, even if the 'src' is bigger than the 'dst' it will be truncated because with strnlen(src, dst_size) the src will be reduced to dst_size length. I made couple tests and could not overflow it(example): cd->fr maximum length is 8: cpywithpad((char *)cd->fr, sizeof(cd->fr), "1.00000090000000000000\0", ' '); the output of cpywithpad: len: 8 is <= dst_size: 8 Same tests I made with mn that has length of 40 adding a string with 244 characters. Sorry my ignorance, but could you give me a better example? Best, -- -- Marcelo Araujo (__)araujo@FreeBSD.org \\\'',)http://www.FreeBSD.org \/ \ ^ Power To Server. .\. /_)