Received: by 2002:a05:7412:37c9:b0:e2:908c:2ebd with SMTP id jz9csp1416463rdb; Wed, 20 Sep 2023 08:32:17 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHfqTsw8kwpb+fC9k8WO83u1GofivsuQPPnHwoNLI+XOqKe+5NmU2hKz+uf+JSQNhtzapsl X-Received: by 2002:a05:6a21:a599:b0:159:fe1d:2f09 with SMTP id gd25-20020a056a21a59900b00159fe1d2f09mr3608970pzc.6.1695223937195; Wed, 20 Sep 2023 08:32:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695223937; cv=none; d=google.com; s=arc-20160816; b=HsjeqlT9YeT46gStrfMUrW98hf04YMNgnutDRJC+vp12cfCE5p/iao8EUUm8SdZDmE 9moKkYHTD9M5bBUbsD6Fh1F4lZBwZBV9hg1z34A3KOZvNDrSmNslnkdFtblmN3FII9iR IxuRaT8ef/YiMKBgucl9JrwjizqjLUQiEgeUxa0J0zqVtWCWWtVWLfg0nhdPbnMzhUjh kbcaMnZlHSr7BcO7BO82SNFgxl2yuMo7YixTqjcpYmMb0dmJk6tIG4twSymNx3Ll75wW 5bLgbl11kIxpXmS6x9gvLCxOw9VZJSDIU+W25aOgOHbaD5xpnYnUP+nRwvkqsRff4onQ yFEA== 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-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=TkhkA2wta3b3NnYgpjyzB6TnKV7qIEnsiYZxlZsQF+0=; fh=JU/DieH71vfjjiMg3GZ+tPr0zZAJT8iz0cM7NtTXgBo=; b=kHbUQTJyy3ghEQ03gKU2m1hdlgTrzOhMDQQ8qIVkJ9upLJs6BTA/GQxb+mNo8YAQmI 022+lOpEYAVFz+gvqRXTz+poLy0czlsO05wiRepTgwd61JJQgTL5NRJJe0602mYoU6dt yB4ompQK9XCLJY3B5/WW8ge01feLdKhrE6mQcStOFwLdulgmxYlIDseEegdY0amxqZPX yZaf3bSsb1qOSGNO4ZHZxfpR68iJ3mo0FFFWnj5NRxTmWDMhQkdtyC0aY2oexcXc9Cs8 gHIXS9MuYo+TG2SbGw47uaMaZrx4zVq1PxA5Ld8iDUBp/IBoc/4L4RLENjNcDl0x+KmI 9eKw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=MBdva0ez; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 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. [2620:137:e000::3:1]) by mx.google.com with ESMTPS id g22-20020a056a000b9600b0069024c6a9acsi12250669pfj.314.2023.09.20.08.32.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Sep 2023 08:32:17 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) client-ip=2620:137:e000::3:1; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=MBdva0ez; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 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 C6D23823F5DA; Wed, 20 Sep 2023 08:23:28 -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 S234610AbjITPX0 (ORCPT + 99 others); Wed, 20 Sep 2023 11:23:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43722 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234923AbjITPXY (ORCPT ); Wed, 20 Sep 2023 11:23:24 -0400 Received: from mail-pl1-x62f.google.com (mail-pl1-x62f.google.com [IPv6:2607:f8b0:4864:20::62f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E029CC6 for ; Wed, 20 Sep 2023 08:23:17 -0700 (PDT) Received: by mail-pl1-x62f.google.com with SMTP id d9443c01a7336-1c5cd27b1acso752965ad.2 for ; Wed, 20 Sep 2023 08:23:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1695223397; x=1695828197; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=TkhkA2wta3b3NnYgpjyzB6TnKV7qIEnsiYZxlZsQF+0=; b=MBdva0ezy4aH5hxL1+DeYTAUe3ISol840sUrBUofMMQKIdLvYFAC5Un/VEDjht7Si+ zJvRYYRG/9XGGGO36A78OwUoHuUHiYuuEi/7PuVznt0Kxw6bmEdcEPpElwwkG0M5gq7w f3I+ry/f75MNL8IuoHJnNta5pU420+/ZZdP7U= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695223397; x=1695828197; h=in-reply-to: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=TkhkA2wta3b3NnYgpjyzB6TnKV7qIEnsiYZxlZsQF+0=; b=eNQ+e+o8nFn7/u4zbGafJfYeAD9F6BK7IVQYEdbuuR2N/svR/Q1l5CBDEIggEJ0veB WRDSBqKq0V7TKRixmbWCbTncdlUl4Q6emJLX2DJL9X28mONKGyv9LZ3zKsdBVK9ZU6bM fbWpNy69wRlL+8Zw4G3BZDuwvyK83B2IBOFGa3LfwN0nvjQaYfE3d7jpu+/29zf0zVlJ 0UVB8Zcg8Xe3NBh7EjRrROG0yZrbYLTj8IkDQVeanG3+hP756LXYqjr3MqeNanEbNFDy gkIJM3M8oYP0XRCa2lP4ZHEz8wH/vdEGd8XFUntuc2yR3CRM+I4R7q98kbBsY5F7+PQT /hVw== X-Gm-Message-State: AOJu0Yzx2nB0G9Pc2GPVUhoGkcQE3vKeOdh3z4RnJV/Ry3aiQkr9c9sM giySLqFREORVXxu5wF458APcYg== X-Received: by 2002:a17:902:ea04:b0:1bf:4a1f:2b57 with SMTP id s4-20020a170902ea0400b001bf4a1f2b57mr3039215plg.13.1695223397249; Wed, 20 Sep 2023 08:23:17 -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 iz17-20020a170902ef9100b001bbf7fd354csm998170plb.213.2023.09.20.08.23.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Sep 2023 08:23:16 -0700 (PDT) Date: Wed, 20 Sep 2023 08:23:16 -0700 From: Kees Cook To: Justin Stitt Cc: Bence =?iso-8859-1?B?Q3Pza+Fz?= , Andi Shyti , linux-i2c@vger.kernel.org, linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org Subject: Re: [PATCH] i2c: cp2615: replace deprecated strncpy with strscpy Message-ID: <202309200822.67A5B4B61@keescook> References: <20230920-strncpy-drivers-i2c-busses-i2c-cp2615-c-v1-1-11406a996794@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230920-strncpy-drivers-i2c-busses-i2c-cp2615-c-v1-1-11406a996794@google.com> 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]); Wed, 20 Sep 2023 08:23:28 -0700 (PDT) On Wed, Sep 20, 2023 at 08:08:52AM +0000, Justin Stitt wrote: > `strncpy` is deprecated for use on NUL-terminated destination strings [1]. > > We should prefer more robust and less ambiguous string interfaces. > > We expect name to be NUL-terminated based on its numerous uses with > functions that expect NUL-terminated strings. > > For example in i2c-core-base.c +1533: > | dev_dbg(&adap->dev, "adapter [%s] registered\n", adap->name); > > NUL-padding is not required as `adap` is already zero-alloacted with: > | adap = devm_kzalloc(&usbif->dev, sizeof(struct i2c_adapter), GFP_KERNEL); > > With the above in mind, a suitable replacement is `strscpy` [2] due to > the fact that it guarantees NUL-termination on the destination buffer > without unnecessarily NUL-padding. > > Link: https://www.kernel.org/doc/html/latest/process/deprecated.html#strncpy-on-nul-terminated-strings [1] > Link: https://manpages.debian.org/testing/linux-manual-4.8/strscpy.9.en.html [2] > Link: https://github.com/KSPP/linux/issues/90 > Cc: linux-hardening@vger.kernel.org > Signed-off-by: Justin Stitt Thanks for the clear commit log! Looks good to me. Reviewed-by: Kees Cook -- Kees Cook