Received: by 2002:a05:7412:f690:b0:e2:908c:2ebd with SMTP id ej16csp1212316rdb; Fri, 20 Oct 2023 11:31:27 -0700 (PDT) X-Google-Smtp-Source: AGHT+IG5muVHnhMrnPB2HFjEHDAwWv7FGLp2+E/YuWiBjRyzBoefnecip1tO6dvOpI9uSSbrDyhs X-Received: by 2002:a05:6a20:8421:b0:14c:910d:972d with SMTP id c33-20020a056a20842100b0014c910d972dmr3430234pzd.12.1697826686701; Fri, 20 Oct 2023 11:31:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697826686; cv=none; d=google.com; s=arc-20160816; b=tFriAwJTB74GWGwGdTzBYcVDo0S1/hwSk96gSWVKJI0MvAPs2Fjxo5URikNdmaeE0z 8cNOPHzCGtzAY8DXS3rduSlpW27cNL8dbcZAYpDz6XRvEcKo+JA7QLhQqQzSGGgr8Yhr EqN5K7/hNvJlHN1ijHP/NA4wrQbDVgN+Let0tLBKXzQFindaJGuekB+X31g/lOMl1Ill /5O4+U5P73KgrzKNqS5AFbOD1iVS2poXIBgLxfaq8OR0vq3UafBBzCOhtLj59H02Kk1x gR2vxt42Bd6824PJVCDEWG7DJQvg/J5xy3iFcTUqySxIunctQxI5xq8ueRnVwiuWKmqW uSxA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=cZuRq2gL8uMCs3ZHk4SNfObSI+VLtMFw8GdVz2Oq9JI=; fh=PTU+KAwjjs8OGo5r07lWHPtCKbsHUCDiLJmjAcyNddQ=; b=rqgY3hT8tTqIIHwhuyndVHda0npFmFti3MhlL7UEXxB4mWbryaccmMpksW99rT4+6G Q3zTpARSxMm+EFChmTsxgdpjgOGnabvpHBJEYTCluPz1gGsr9pMDq/sUJURHRBEr3NTf V7Vmqdpix2E7be7W/D4JffRt2eTZxsU5eirc82CqdQOYBDTtixLqZRUGrE1v7vtdW7bd FsIFqKy5ruDxNP0RcC11VZ6b/y2mqvPYGNIPZKgHF1OFmsyn0deOcCwtsIaboAaza0bN KIxpeOdxlR0Q5lKRo1xKjASyznNr0QfmFMFTm5jJwdfqwcA4filoNnBvpTht4nfVpC5y LVrA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=L6KOYpZg; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from morse.vger.email (morse.vger.email. [23.128.96.31]) by mx.google.com with ESMTPS id s24-20020a056a00179800b006bd7cfa8497si2498783pfg.83.2023.10.20.11.31.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Oct 2023 11:31:26 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) client-ip=23.128.96.31; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=L6KOYpZg; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by morse.vger.email (Postfix) with ESMTP id 44C868346DCD; Fri, 20 Oct 2023 11:31:00 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229660AbjJTSay (ORCPT + 99 others); Fri, 20 Oct 2023 14:30:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53234 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229473AbjJTSax (ORCPT ); Fri, 20 Oct 2023 14:30:53 -0400 Received: from mail-pl1-x632.google.com (mail-pl1-x632.google.com [IPv6:2607:f8b0:4864:20::632]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 08541106 for ; Fri, 20 Oct 2023 11:30:51 -0700 (PDT) Received: by mail-pl1-x632.google.com with SMTP id d9443c01a7336-1ca72f8ff3aso9206115ad.0 for ; Fri, 20 Oct 2023 11:30:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1697826650; x=1698431450; darn=vger.kernel.org; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date:from:to :cc:subject:date:message-id:reply-to; bh=cZuRq2gL8uMCs3ZHk4SNfObSI+VLtMFw8GdVz2Oq9JI=; b=L6KOYpZgmtlJXbw7dGwbdQ/zW7iCiULHX7NQcRahENgJVTcZcHQvtuITNSzTvqpojl nRwJ9YS++RgRHIKnHBZ47XwpMVEo5zBb/2qYXKWrnctpDXP2WtPi35QN6RMCm+BeUfmH EYXL+AZ95/i01liMAM/2jOcCrKR2gP5YlNzOw= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697826650; x=1698431450; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=cZuRq2gL8uMCs3ZHk4SNfObSI+VLtMFw8GdVz2Oq9JI=; b=SMD5fijSQlrg7tWKlqT9U/qfPIOzySHy9BwsIEKQT2jI2jVD1zIhj0R1QeNqRLjgKF Q+KrwQMzQU5FXxYWJk08o1+o1EP2HaPRT4fRHgT9Y/EK35+WQQtkE407lQj71zL06Wjh NA+mCxCVaSgWpJ7AdB0Zqjxrti5854zcIZfP/Vcr60+mq3mSQDJB7krQ8TR7FmGFodWG ci/OwyLSQwjbG2qZycsnUsxs63fZfdsFIHP0z+3d41/gXOznzOc0J7q3ypN/+CSueF0I 9pgYP7rfpy6gwBDBpwHFeXuKpnmBHA8GFOkBKC4jCyI8RqSAi+6yRvOWrWNzE20WdAlE F6sA== X-Gm-Message-State: AOJu0YwW6ysVdtRhb6q4YNqMPSmZ6sZLZ38agP8uur65fdOYSQrMMr53 PwclKzA9V06C1KLRohsC7f4hYA== X-Received: by 2002:a17:902:e5d0:b0:1c9:e2ed:66fe with SMTP id u16-20020a170902e5d000b001c9e2ed66femr2549273plf.52.1697826650428; Fri, 20 Oct 2023 11:30:50 -0700 (PDT) Received: from www.outflux.net (198-0-35-241-static.hfc.comcastbusiness.net. [198.0.35.241]) by smtp.gmail.com with ESMTPSA id jc15-20020a17090325cf00b001c746b986e5sm1839961plb.45.2023.10.20.11.30.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Oct 2023 11:30:49 -0700 (PDT) Date: Fri, 20 Oct 2023 11:30:49 -0700 From: Kees Cook To: Christoph Hellwig Cc: Justin Stitt , Keith Busch , Jens Axboe , Sagi Grimberg , linux-nvme@lists.infradead.org, linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org, ksummit@lists.linux.dev Subject: Re: the nul-terminated string helper desk chair rearrangement Message-ID: <202310201127.DA7EDAFE4D@keescook> References: <20231018-strncpy-drivers-nvme-host-fabrics-c-v1-1-b6677df40a35@google.com> <20231019054642.GF14346@lst.de> <202310182248.9E197FFD5@keescook> <20231020044645.GC11984@lst.de> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on morse.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (morse.vger.email [0.0.0.0]); Fri, 20 Oct 2023 11:31:00 -0700 (PDT) On Fri, Oct 20, 2023 at 10:40:12AM -0700, Justin Stitt wrote: > On Thu, Oct 19, 2023 at 9:46 PM Christoph Hellwig wrote: > > > > On Wed, Oct 18, 2023 at 11:01:54PM -0700, Kees Cook wrote: > > > Almost all of the remaining strncpy() usage is just string to string > > > copying, but the corner cases that are being spun out that aren't > > > strscpy() or strscpy_pad() are covered by strtomem(), kmemdup_nul(), > > > and memcpy(). Each of these are a clear improvement since they remove > > > the ambiguity of the intended behavior. Using seq_buf ends up being way > > > more overhead than is needed. > > > > I'm really not sure strscpy is much of an improvement. In this particular > > case in most other places we simply use a snprintf for nqns, which seems > > useful here to if we don't want the full buf. > > > > But switching to a completely undocumented helper like strscpy seems not > > useful at all. I'm curious where you looked and didn't find documentation -- perhaps there is an improvement to be made to aim one to where the existing documentation lives? > > There's some docs at [1]. Perhaps there could be more? > > [1]: https://elixir.bootlin.com/linux/v6.6-rc6/source/include/linux/fortify-string.h#L292 Right, And it's even valid kern-doc, which gets rendered in the kernel API docs, along with all the other string functions: https://docs.kernel.org/core-api/kernel-api.html#c.strscpy -- Kees Cook