Received: by 2002:a05:7412:251c:b0:e2:908c:2ebd with SMTP id w28csp2221973rda; Tue, 24 Oct 2023 16:59:07 -0700 (PDT) X-Google-Smtp-Source: AGHT+IE9FelWqqQ2gbVmrTaK7UhymIKvhjjN/qrXoBf5naPLlht77GjY2bOGQMX2zAuvUc22V6sX X-Received: by 2002:a05:6a20:3d14:b0:163:9f1d:b464 with SMTP id y20-20020a056a203d1400b001639f1db464mr4272780pzi.5.1698191947025; Tue, 24 Oct 2023 16:59:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698191947; cv=none; d=google.com; s=arc-20160816; b=tpHZEbPGuwBfFDPBYrtzJw4BpuEvjMMv5t9XPHXGMXJd4h15CSQbMgwfAAO2iusp1R v+3FqgpE4qZBDkKnlWZpwfvXSuIDjCoKvChumdFoNf/IRlawFpMOAIIOKWocUxYCkmVY X8/4vNuLc9+szzdf+K1LOxIbXgAjGwob+gkuyH0bF9UkXESKQza/vKBUiQal8Pzw9zVZ SlnTDR3We5XuOIZeO2aoidl9qzf3dKUBWCcO300/1mKG1wJ8GDzGdA2Lw2UKItPnHuRZ gUxvuOr1TCnNPXtf2DMk5I+IBu9JqF7PVbEqzJR7jEzG09QAbDxPhdyU43KqFVAzRmOM O7iQ== 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=wXs6Pn0q7dHLwrvjv/VGOUkBCbTosuxQIWXIR0FEvR8=; fh=hoqVShFmEVja86CV/BifOFMg5DmDMcQ4iG0LLQrURLE=; b=g8It3+Ecbc84J11TighL3vd0kDpUZrNcLmr34C740EAxZ+fCHQPbg5i0MmKw/ogNXW ySIv0Hg+yFOZNVzuMZwIgVPQ6aQ6F47I5mm56SdAuCBTfhNg0+ZfprygTK4PVDYfDQZU b9pnI3RsOfbG9Iewz69Rnhtahz4z5jhL+o+jINYDDpLdHu2z1YdE8qTvIAS1EW4/t7a4 v3ncmsdGRJ37UJJ1HlvD2oLXLMDR2/B6MiM4PTBFYKY+NHqqZkEIK0nL6In8nd3rEpE1 /mxrfbav5G2Rsn4Oi+zp8Cvy8GmnYzTb/kqIdg+euw1LgOdvXCfq5GzwVGSEjzckLTs6 vakg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=BzzD391t; 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 t15-20020a056a00138f00b006b905fe37b7si9459985pfg.221.2023.10.24.16.59.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Oct 2023 16:59:07 -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=BzzD391t; 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 A2E2280219F7; Tue, 24 Oct 2023 16:59:04 -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 S1344663AbjJXX64 (ORCPT + 99 others); Tue, 24 Oct 2023 19:58:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37240 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344685AbjJXX6y (ORCPT ); Tue, 24 Oct 2023 19:58:54 -0400 Received: from mail-pf1-x431.google.com (mail-pf1-x431.google.com [IPv6:2607:f8b0:4864:20::431]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 18AA710CF for ; Tue, 24 Oct 2023 16:58:52 -0700 (PDT) Received: by mail-pf1-x431.google.com with SMTP id d2e1a72fcca58-6b26a3163acso4047562b3a.2 for ; Tue, 24 Oct 2023 16:58:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1698191931; x=1698796731; 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=wXs6Pn0q7dHLwrvjv/VGOUkBCbTosuxQIWXIR0FEvR8=; b=BzzD391tHqE+Hh/rRCeKA7EZQdyRdcIn4BHeNGuTVkQKk08DUb5mxdxrKzkHv/a/4L 3LaLEdnSWG93YvE2yGrPXNy9IKB/ASVMIVyop33GDMXSzbvUd7SnEx2Chn9S5KrdrRs4 9Bqqs/WN0UVpUVupuPB0OiHqheYkFkveUT3FE= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698191931; x=1698796731; 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=wXs6Pn0q7dHLwrvjv/VGOUkBCbTosuxQIWXIR0FEvR8=; b=ful6oIhAKWP0Sig7I5UpT+KQUeKoSYCspxw8gWbarUF05rHhXnlRLj/c4Dcgjcz2PQ c9/kfI8GzHV6/pJ3FfUGpzejWjQdxozWRquqRb5CKOVYcmdyQ6LB6KvQPab0LckuE3Bm NW9X4NyBP8uOnJuuxeS7EdznhH+bhmQrq+FxfhIq/K3HIo0FYVYs1Iw/6tfNNDfYSo2p U6Sn0lJmtz24pRPYawtSL/YycuO20049LbDu4NzvYJ3q+KPBgwFq7bAdD+1vnAF4V/8Q FkYhiJg2No6vU4fvYEOLuTZzsTunXVxXh1dqzipU9K6PpvBXVZPzwaBST/z7OL0348/E yS6w== X-Gm-Message-State: AOJu0YyPPFEHgAAZ8xzZurEQAS2JJB6zC4Sc24VS/ieaecgwneQCVhGD Q94IonGC2A+HZC5R4NHxHpx5gg== X-Received: by 2002:aa7:991e:0:b0:6b8:2ef3:331d with SMTP id z30-20020aa7991e000000b006b82ef3331dmr10232303pff.10.1698191931447; Tue, 24 Oct 2023 16:58:51 -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 f11-20020aa79d8b000000b006b4a5569694sm8099281pfq.83.2023.10.24.16.58.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Oct 2023 16:58:50 -0700 (PDT) Date: Tue, 24 Oct 2023 16:58:50 -0700 From: Kees Cook To: Justin Stitt Cc: Vineeth Vijayan , Peter Oberparleiter , Heiko Carstens , Vasily Gorbik , Alexander Gordeev , Christian Borntraeger , Sven Schnelle , linux-s390@vger.kernel.org, linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org Subject: Re: [PATCH] s390/cio: replace deprecated strncpy with strscpy Message-ID: <202310241658.0144D73@keescook> References: <20231023-strncpy-drivers-s390-cio-chsc-c-v1-1-8b76a7b83260@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20231023-strncpy-drivers-s390-cio-chsc-c-v1-1-8b76a7b83260@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]); Tue, 24 Oct 2023 16:59:04 -0700 (PDT) On Mon, Oct 23, 2023 at 07:24:38PM +0000, Justin Stitt wrote: > strncpy() is deprecated for use on NUL-terminated destination strings > [1] and as such we should prefer more robust and less ambiguous string > interfaces. > > We expect both `params` and `id` to be NUL-terminated based on their > usage with format strings: > > format_node_data(iuparams, iunodeid, &lir->incident_node); > format_node_data(auparams, aunodeid, &lir->attached_node); > > switch (lir->iq.class) { > case LIR_IQ_CLASS_DEGRADED: > pr_warn("Link degraded: RS=%02x RSID=%04x IC=%02x " > "IUPARAMS=%s IUNODEID=%s AUPARAMS=%s AUNODEID=%s\n", > sei_area->rs, sei_area->rsid, lir->ic, iuparams, > iunodeid, auparams, aunodeid); > > NUL-padding is not required as both `params` and `id` have been memset > to 0: > > memset(params, 0, PARAMS_LEN); > memset(id, 0, NODEID_LEN); > > Considering the above, a suitable replacement is `strscpy` [2] due to > the fact that it guarantees NUL-termination on the destination buffer > without unnecessarily NUL-padding. > > Note that there's no overread bugs in the current implementation as the > string literal "n/a" has a size much smaller than PARAMS_LEN or > NODEID_LEN. Nonetheless, let's favor strscpy(). > > 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 Looks good. Reviewed-by: Kees Cook -- Kees Cook