Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp540381ybi; Thu, 13 Jun 2019 22:22:16 -0700 (PDT) X-Google-Smtp-Source: APXvYqxuyCe7OoWNZ/bn3qidrZet4Ek8mql3NZZAEvETOx3b1/Lh9O+bkkxkxS/jC/NyhX2YOIE3 X-Received: by 2002:aa7:8d8c:: with SMTP id i12mr68354428pfr.200.1560489736165; Thu, 13 Jun 2019 22:22:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1560489736; cv=none; d=google.com; s=arc-20160816; b=BhGkkUSVLoG0T0MciJal85xVe4kCmQbo9g5ny78XmldQLkHpg48SeDjNAV/x7WtFQq n+c3FWIaONKRT6ECpyK4irl4+lcb8kvHDDuYrPiiQNTJ1kaGIuOcEgDfRsz4XBYsTVxS 9YuZuma35pr7dveJSuux4cgERi9QsMhZUITcFzzr7uDIBWtcC0Dk2g645qITpoGWe/Lv VLykE2luFYj97/cmov/ViNcGZkLjAukbQ1I+ItO0F72Ols7SqxlnGxbvvCxCnxnswiDP W26GGTZ9zXeqLqGQdzSAEmf5QSHws3+NqgXvbZobYaXRT9+JULcRQTzrpUHDFf1mp7wC Zvmg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=eaKV7EziIjndV6AC+P0Sj4AtYTr8nO2QSc+wtuDvkUw=; b=f57vKlpYlqNZnrfgBWV3KYzRMXhiyrOYbbOb9vb59IiF1hzxyhGU5ELU2l5tD6hpOt aQ9zWT3QOqMll/oTTIM3uoMmG5Dbwd1dG+kRQyDEVmAVnYPB3cJwdCsZ+T5ny5awyrno lh89fgIjVeDgNXonRt0Rn5MzQXtN0oInUR0RrMp8MsynLHYHd1rsijk6M/6zOwpUS8Sp pCUEH9mIaW38qJPMe0YKX9gpzMb9XoXtdtGGi+9jTd5Tcwb9cM7npHPqV54xT9v20E/R pOk5pZ5J0ZETT45l/Zrlx+bvnr2yeIcjTpcRGroJiIEfSEFP4xoo9hfq5E+VVWcYszbm TSeA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b="UgUE3/10"; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id g7si1208282plo.42.2019.06.13.22.22.00; Thu, 13 Jun 2019 22:22:16 -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; dkim=pass header.i=@chromium.org header.s=google header.b="UgUE3/10"; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725907AbfFNFUk (ORCPT + 99 others); Fri, 14 Jun 2019 01:20:40 -0400 Received: from mail-pl1-f193.google.com ([209.85.214.193]:33167 "EHLO mail-pl1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725864AbfFNFUk (ORCPT ); Fri, 14 Jun 2019 01:20:40 -0400 Received: by mail-pl1-f193.google.com with SMTP id c14so513433plo.0 for ; Thu, 13 Jun 2019 22:20:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=eaKV7EziIjndV6AC+P0Sj4AtYTr8nO2QSc+wtuDvkUw=; b=UgUE3/10eslkNJLEV8hF7ZLG4ONsqW43pl12koi4wIm54HP6r9Srh8N6xE3arEvqKY bQHE6BgI2k0MjeMk6m2a8QxdCa+0roxNFBco4POjtlHM8aRCN2dYHqFvzWKGrNrQhwrr YBHjPW6i27j6mOfTr37z4CA6/5iwbosmGOY1Q= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=eaKV7EziIjndV6AC+P0Sj4AtYTr8nO2QSc+wtuDvkUw=; b=Yner1tGpbk7GkBpcawTNzo3JVmRI0DvYRw2zmzV8yxD377F/e31o09Dnopzgu0o7ea Hv733cjt3AsQFsGtCKtVCyIty79gmKfxrRyl1dfcO7Fojj2GKjkaQUgVcosMNNTmcDWc tYuQqIhQQZeqKg+RkJBoH1mHvRFP7PutogxScCWIVmkwuiAy9UI3mwejWR3oJ2w+o8gi ukwdaQP7XD3MN/SDXtOkVrmHNNneBcCmf05fTfgBmKV3wh4DGovFNekSKLgzffRLCyrs fnajje70Zi92eSQh2//K7E6Pi6zaimxSDmAIMYVRZOclHBK71vpd+zT6eiYQyZpL9vMr 9U5Q== X-Gm-Message-State: APjAAAWHoolyFQjYcgP7qVRigY+Id2idAA3HmXAhORBbFXnM+1ckHMhs /ySGGCLQrej/Cbr6Jae9eCOQog== X-Received: by 2002:a17:902:6902:: with SMTP id j2mr19043580plk.321.1560489639574; Thu, 13 Jun 2019 22:20:39 -0700 (PDT) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id h11sm1382699pfn.170.2019.06.13.22.20.38 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 13 Jun 2019 22:20:38 -0700 (PDT) Date: Thu, 13 Jun 2019 22:20:37 -0700 From: Kees Cook To: Stephen Kitt Cc: corbet@lwn.net, federico.vaga@vaga.pv.it, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] docs: stop suggesting strlcpy Message-ID: <201906132220.F12C1111@keescook> References: <20190613162548.19792-1-steve@sk2.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190613162548.19792-1-steve@sk2.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Jun 13, 2019 at 06:25:48PM +0200, Stephen Kitt wrote: > Since strlcpy is deprecated, the documentation shouldn't suggest using > it. This patch fixes the examples to use strscpy instead. It also uses > sizeof instead of underlying constants as far as possible, to simplify > future changes to the corresponding data structures. > > Signed-off-by: Stephen Kitt Yes please! Acked-by: Kees Cook -Kees > --- > Documentation/hid/hid-transport.txt | 6 +++--- > Documentation/i2c/instantiating-devices | 2 +- > Documentation/i2c/upgrading-clients | 4 ++-- > Documentation/kernel-hacking/locking.rst | 6 +++--- > Documentation/translations/it_IT/kernel-hacking/locking.rst | 6 +++--- > 5 files changed, 12 insertions(+), 12 deletions(-) > > diff --git a/Documentation/hid/hid-transport.txt b/Documentation/hid/hid-transport.txt > index 3dcba9fd4a3a..4f41d67f1b4b 100644 > --- a/Documentation/hid/hid-transport.txt > +++ b/Documentation/hid/hid-transport.txt > @@ -194,9 +194,9 @@ with HID core: > goto err_<...>; > } > > - strlcpy(hid->name, , 127); > - strlcpy(hid->phys, , 63); > - strlcpy(hid->uniq, , 63); > + strscpy(hid->name, , sizeof(hid->name)); > + strscpy(hid->phys, , sizeof(hid->phys)); > + strscpy(hid->uniq, , sizeof(hid->uniq)); > > hid->ll_driver = &custom_ll_driver; > hid->bus = ; > diff --git a/Documentation/i2c/instantiating-devices b/Documentation/i2c/instantiating-devices > index 0d85ac1935b7..8bc7d99133e3 100644 > --- a/Documentation/i2c/instantiating-devices > +++ b/Documentation/i2c/instantiating-devices > @@ -137,7 +137,7 @@ static int usb_hcd_nxp_probe(struct platform_device *pdev) > (...) > i2c_adap = i2c_get_adapter(2); > memset(&i2c_info, 0, sizeof(struct i2c_board_info)); > - strlcpy(i2c_info.type, "isp1301_nxp", I2C_NAME_SIZE); > + strscpy(i2c_info.type, "isp1301_nxp", sizeof(i2c_info.type)); > isp1301_i2c_client = i2c_new_probed_device(i2c_adap, &i2c_info, > normal_i2c, NULL); > i2c_put_adapter(i2c_adap); > diff --git a/Documentation/i2c/upgrading-clients b/Documentation/i2c/upgrading-clients > index ccba3ffd6e80..96392cc5b5c7 100644 > --- a/Documentation/i2c/upgrading-clients > +++ b/Documentation/i2c/upgrading-clients > @@ -43,7 +43,7 @@ static int example_attach(struct i2c_adapter *adap, int addr, int kind) > example->client.adapter = adap; > > i2c_set_clientdata(&state->i2c_client, state); > - strlcpy(client->i2c_client.name, "example", I2C_NAME_SIZE); > + strscpy(client->i2c_client.name, "example", sizeof(client->i2c_client.name)); > > ret = i2c_attach_client(&state->i2c_client); > if (ret < 0) { > @@ -138,7 +138,7 @@ can be removed: > - example->client.flags = 0; > - example->client.adapter = adap; > - > -- strlcpy(client->i2c_client.name, "example", I2C_NAME_SIZE); > +- strscpy(client->i2c_client.name, "example", sizeof(client->i2c_client.name)); > > The i2c_set_clientdata is now: > > diff --git a/Documentation/kernel-hacking/locking.rst b/Documentation/kernel-hacking/locking.rst > index 519673df0e82..dc698ea456e0 100644 > --- a/Documentation/kernel-hacking/locking.rst > +++ b/Documentation/kernel-hacking/locking.rst > @@ -451,7 +451,7 @@ to protect the cache and all the objects within it. Here's the code:: > if ((obj = kmalloc(sizeof(*obj), GFP_KERNEL)) == NULL) > return -ENOMEM; > > - strlcpy(obj->name, name, sizeof(obj->name)); > + strscpy(obj->name, name, sizeof(obj->name)); > obj->id = id; > obj->popularity = 0; > > @@ -660,7 +660,7 @@ Here is the code:: > } > > @@ -63,6 +94,7 @@ > - strlcpy(obj->name, name, sizeof(obj->name)); > + strscpy(obj->name, name, sizeof(obj->name)); > obj->id = id; > obj->popularity = 0; > + obj->refcnt = 1; /* The cache holds a reference */ > @@ -774,7 +774,7 @@ the lock is no longer used to protect the reference count itself. > } > > @@ -94,7 +76,7 @@ > - strlcpy(obj->name, name, sizeof(obj->name)); > + strscpy(obj->name, name, sizeof(obj->name)); > obj->id = id; > obj->popularity = 0; > - obj->refcnt = 1; /* The cache holds a reference */ > diff --git a/Documentation/translations/it_IT/kernel-hacking/locking.rst b/Documentation/translations/it_IT/kernel-hacking/locking.rst > index 0ef31666663b..5fd8a1abd2be 100644 > --- a/Documentation/translations/it_IT/kernel-hacking/locking.rst > +++ b/Documentation/translations/it_IT/kernel-hacking/locking.rst > @@ -468,7 +468,7 @@ e tutti gli oggetti che contiene. Ecco il codice:: > if ((obj = kmalloc(sizeof(*obj), GFP_KERNEL)) == NULL) > return -ENOMEM; > > - strlcpy(obj->name, name, sizeof(obj->name)); > + strscpy(obj->name, name, sizeof(obj->name)); > obj->id = id; > obj->popularity = 0; > > @@ -678,7 +678,7 @@ Ecco il codice:: > } > > @@ -63,6 +94,7 @@ > - strlcpy(obj->name, name, sizeof(obj->name)); > + strscpy(obj->name, name, sizeof(obj->name)); > obj->id = id; > obj->popularity = 0; > + obj->refcnt = 1; /* The cache holds a reference */ > @@ -792,7 +792,7 @@ contatore stesso. > } > > @@ -94,7 +76,7 @@ > - strlcpy(obj->name, name, sizeof(obj->name)); > + strscpy(obj->name, name, sizeof(obj->name)); > obj->id = id; > obj->popularity = 0; > - obj->refcnt = 1; /* The cache holds a reference */ > -- > 2.11.0 > -- Kees Cook