From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 24A9F21A15 for ; Mon, 25 Sep 2023 18:04:36 +0000 (UTC) Received: from mail-yb1-xb2f.google.com (mail-yb1-xb2f.google.com [IPv6:2607:f8b0:4864:20::b2f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C75B69B for ; Mon, 25 Sep 2023 11:04:34 -0700 (PDT) Received: by mail-yb1-xb2f.google.com with SMTP id 3f1490d57ef6-d8673a90f56so4456855276.0 for ; Mon, 25 Sep 2023 11:04:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1695665074; x=1696269874; 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=XftFOjpvnqBOvm+GyG7dS3QneDyHgJbjgRAoI+rP2Vc=; b=hR7fPoA9GHElMqHoCR+hCqcwl2hviY1cJs0/p9nCUFs0yEqkiUApK5fs84WUphxHuA 3aRBZCaEeIn03MsA8ev3tuaBgLG5GPGQmLGgbnT4XnJbPcBxz0KqPCzXlFF2sIX94x96 N/GfDflSXS3ODCqdCmMuzXPTr9WPBuk8Z51rY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695665074; x=1696269874; 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=XftFOjpvnqBOvm+GyG7dS3QneDyHgJbjgRAoI+rP2Vc=; b=YUAu+eGjvSMsyUwaMM1bMaft12PQkS9FuMP1VlCik/8Zy4pVzDg2UG8sRzctMyVFpK p96383c/mDZfi0WkKTg7n52un5pi4cTMfTnlhh2Wqapp8AiFC3D1qKv2WmBc6tWoEAQn Lve/tAxFSwjBw+ArSgdPhGEy6r8Ql4159lhHAmhjpMaEwZdsfvnWXbrzkU1ejrQO1i7L 3P954vsFWmpQPpYKlI+DkKfvHPBX0Sok6or/w24RiX87DmlPwsw2kmn13l52myVc/T3l lMQGUzOCSZQpDkoFU/bNJ1yFC5jt792BrF9bM8ZL+NuTFPJR6FzZuHdrNYiz0sDSPvIg BnYQ== X-Gm-Message-State: AOJu0Yx6PGnShyyA5R8bGHYDOhRYjYYI9j9QvhlTyC50rXPgAmrD/UKO 0r3peZJVsv9Uv5cbKwS493nYfQ== X-Google-Smtp-Source: AGHT+IHLxOCMidSuiT5VuJdY2s//GNKCUPI3HgEunXnWS6HNGof+bL6k1SeyWqZzqivG9gVlZPGyJQ== X-Received: by 2002:a25:838e:0:b0:d7f:e578:58d5 with SMTP id t14-20020a25838e000000b00d7fe57858d5mr6401728ybk.41.1695665073996; Mon, 25 Sep 2023 11:04:33 -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 j19-20020a633c13000000b00565009a97f0sm8168514pga.17.2023.09.25.11.04.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Sep 2023 11:04:33 -0700 (PDT) Date: Mon, 25 Sep 2023 11:04:32 -0700 From: Kees Cook To: Justin Stitt Cc: Alasdair Kergon , Mike Snitzer , dm-devel@redhat.com, linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org Subject: Re: [PATCH] dm crypt: replace open-coded kmemdup_nul Message-ID: <202309251104.2039A045E@keescook> References: <20230925-strncpy-drivers-md-dm-crypt-c-v1-1-eef875e4f9b2@google.com> Precedence: bulk X-Mailing-List: linux-hardening@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230925-strncpy-drivers-md-dm-crypt-c-v1-1-eef875e4f9b2@google.com> X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, RCVD_IN_DNSWL_BLOCKED,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 lindbergh.monkeyblade.net On Mon, Sep 25, 2023 at 06:35:54AM +0000, Justin Stitt wrote: > kzalloc() followed by strncpy() on an expected NUL-terminated string is > just kmemdup_nul(). Let's simplify this code (while also dropping a > deprecated strncpy() call [1]). > > Link: https://www.kernel.org/doc/html/latest/process/deprecated.html#strncpy-on-nul-terminated-strings [1] > Link: https://github.com/KSPP/linux/issues/90 > Cc: linux-hardening@vger.kernel.org > Cc: Kees Cook > Signed-off-by: Justin Stitt This looks correct to me. Thanks! Reviewed-by: Kees Cook -- Kees Cook