Received: by 2002:a05:7412:31a9:b0:e2:908c:2ebd with SMTP id et41csp4564980rdb; Fri, 15 Sep 2023 06:14:30 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEM6oZV0RK4sxInM+oj0m9mGf5MUX/ENGjKqX9HBrdU62nK2KP7gyOf/3VzcsKuvj8edgsv X-Received: by 2002:a17:903:2345:b0:1b2:5d5b:e871 with SMTP id c5-20020a170903234500b001b25d5be871mr1674079plh.59.1694783670061; Fri, 15 Sep 2023 06:14:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694783670; cv=none; d=google.com; s=arc-20160816; b=jwZSwN28AQ1AAq7ArMEV/kEfIqFxNRi24Q+OE8LH7C5EYN2WbUONolahZhFFwAABat PJi2XY48gqpFNWCI260bA80tiIfeGdPy7lqx392wLX2HQ4ZwipYBufMxMx8TII0jqsBZ O16JY4HJGJcPQn2p78ShiV8mydOvNvwwzfsXHPPj/4IHN4QfSzyA1BoFr0HxWI0HUPBa UsJPTs8fHQqDnrYk0ERy9i7dnqDpfQzFU+S66DSMMO9l+HE/f50DMjQPB4mTYLroAhf6 nl+DYgiFmVf287XvLV+NIBpHSKVChB+CV2drMmRrKMutihOBCz7QkV8K1YSwnaT/CTOI k92w== 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=emL8gA7NYvcjlfqjFCfssMU1Dd1/VuC6P+GxTP1jKsg=; fh=6t4hr+uizomyLhmygCIEwdHeaHVNvQPhR/DJoMqzjTo=; b=sXyXWxrLGZj+7mI/Ok8aQ9jX9QvwnAPRy6RCK1TgfpSbg1mRGanrYj3Ej0kbSGlw2q fWQNRKZnEz6qDfB+EbzomNon3qBWYOIQxB9nFcbIYXawNPciS6J0lgX3lsZ1afy3Srtr LHdP1au8Vou8+VcwDi/gLRtF6doi1g36DsCsQfDRqOpkKWl6gfCr6uhJoWJ4jSTbc6sg Wrkruwpscng0btQzom19cmj29j+IQG89hmDk01vZbWe766EN0qiXHffjwUuvkt+VZvdM YsIPqhkc4/MVQfaOO0Z0jSn8QNUgZY0CacXlUCPyK2U1dWsl91zxgdO53Ma+PHI8b00E KrEQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=MyP9D0dS; spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from groat.vger.email (groat.vger.email. [2620:137:e000::3:5]) by mx.google.com with ESMTPS id c5-20020a170902d48500b001b8ae69289dsi3518632plg.539.2023.09.15.06.14.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Sep 2023 06:14:30 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) client-ip=2620:137:e000::3:5; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=MyP9D0dS; spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) smtp.mailfrom=linux-crypto-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 groat.vger.email (Postfix) with ESMTP id 5618A8316EDA; Thu, 14 Sep 2023 20:40:26 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230292AbjIODk0 (ORCPT + 99 others); Thu, 14 Sep 2023 23:40:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60954 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230519AbjIODkZ (ORCPT ); Thu, 14 Sep 2023 23:40:25 -0400 Received: from mail-pj1-x102d.google.com (mail-pj1-x102d.google.com [IPv6:2607:f8b0:4864:20::102d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D2D371BF4 for ; Thu, 14 Sep 2023 20:40:21 -0700 (PDT) Received: by mail-pj1-x102d.google.com with SMTP id 98e67ed59e1d1-27489f78e52so665834a91.1 for ; Thu, 14 Sep 2023 20:40:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1694749221; x=1695354021; 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=emL8gA7NYvcjlfqjFCfssMU1Dd1/VuC6P+GxTP1jKsg=; b=MyP9D0dSZY+fWf4QeF4UdYcx2K6f4ifR/RvqMLfDWZFAoiEbVe40OpTeNjLZBffFvt PXF/RkkUs9nETu7y8+Ew2+kq2I6i7L2qBiiw/Tsg8kKwUXGfZrPFJEg7v8STx/lEsbl1 jbYqFT/1Z6Db4eklu8RuKWI9x3rSEhtPtA+qc= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694749221; x=1695354021; 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=emL8gA7NYvcjlfqjFCfssMU1Dd1/VuC6P+GxTP1jKsg=; b=nOUzJkM7r/Qe0SSAJrkGpos93FhLjLojDJpMsqNPZqzmLMNcuL1H5ZLF85QNZeNZuf dvP6LOXv1ryM0b+eBmXhSrwhhVh1dJyj0j+pUMVpLUzKoDZn7YscuagsdtShYlSm5sZF 1zclScO56FIs8/GuB1OecU/0TgycKG/qpwhBMwmlNRstJfJo0G2mD6WePk9LEXonIECO KXOzVy8EWJ3eKiXI0a5n/R6R8xqsNlgRNM+xe60ZWjj7TESKasGuv3pH90Oqe2CCXpX+ hS4VQTziYJAx/3NCHRpDrZ64Cgk3QL2eHVYgqfb3jYh5T3uKrGq/Q+9zGFxAHXWeraFM 9FZA== X-Gm-Message-State: AOJu0Yw7YGv7GQShHIBKHaq9w+IB6yK/mEeXoW8Y/Uv4agCLRTEgJxnz 6Xst8L9K5Tl3RckXV0yHxlQ73A== X-Received: by 2002:a17:90b:3583:b0:268:7be6:29a5 with SMTP id mm3-20020a17090b358300b002687be629a5mr373511pjb.9.1694749221378; Thu, 14 Sep 2023 20:40:21 -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 h12-20020a170902748c00b001b246dcffb7sm2330294pll.300.2023.09.14.20.40.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Sep 2023 20:40:20 -0700 (PDT) Date: Thu, 14 Sep 2023 20:40:20 -0700 From: Kees Cook To: Justin Stitt Cc: Giovanni Cabiddu , Herbert Xu , "David S. Miller" , qat-linux@intel.com, linux-crypto@vger.kernel.org, linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org Subject: Re: [PATCH] crypto: qat - refactor deprecated strncpy Message-ID: <202309142039.F903B1C@keescook> References: <20230913-strncpy-drivers-crypto-intel-qat-qat_common-qat_uclo-c-v1-1-88a6c07fc924@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230913-strncpy-drivers-crypto-intel-qat-qat_common-qat_uclo-c-v1-1-88a6c07fc924@google.com> Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (groat.vger.email [0.0.0.0]); Thu, 14 Sep 2023 20:40:26 -0700 (PDT) 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 groat.vger.email On Wed, Sep 13, 2023 at 12:51:05AM +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. > > `buf` is expected to be NUL-terminated for its eventual use in > `kstrtoul()` and NUL-padding is not required. > > Due to the above, a suitable replacement is `strscpy` [2] due to the > fact that it guarantees NUL-termination on the destination buffer. > > 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 > --- > Note: build-tested only. > --- > drivers/crypto/intel/qat/qat_common/qat_uclo.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/drivers/crypto/intel/qat/qat_common/qat_uclo.c b/drivers/crypto/intel/qat/qat_common/qat_uclo.c > index ce837bcc1cab..e2f82128043e 100644 > --- a/drivers/crypto/intel/qat/qat_common/qat_uclo.c > +++ b/drivers/crypto/intel/qat/qat_common/qat_uclo.c > @@ -200,7 +200,7 @@ static int qat_uclo_parse_num(char *str, unsigned int *num) > unsigned long ae = 0; > int i; > > - strncpy(buf, str, 15); > + strscpy(buf, str, sizeof(buf)); > for (i = 0; i < 16; i++) { > if (!isdigit(buf[i])) { I was initially worried when I saw this walking the entire contents, but I see it is explicitly zeroed on the stack first, so this is fine: char buf[16] = {0}; Reviewed-by: Kees Cook -Kees > buf[i] = '\0'; > > --- > base-commit: 2dde18cd1d8fac735875f2e4987f11817cc0bc2c > change-id: 20230913-strncpy-drivers-crypto-intel-qat-qat_common-qat_uclo-c-0f4b16830f59 > > Best regards, > -- > Justin Stitt > -- Kees Cook