Received: by 2002:a05:7412:b10a:b0:f3:1519:9f41 with SMTP id az10csp606814rdb; Thu, 30 Nov 2023 13:11:48 -0800 (PST) X-Google-Smtp-Source: AGHT+IGzhgMAIoZo+7J/tiFqijDwYM76AfZ9tZrtHHl10uQvi6e43zel0yw4g8hd6Suf2Jh3jjE4 X-Received: by 2002:a17:902:ec89:b0:1cf:bd98:6357 with SMTP id x9-20020a170902ec8900b001cfbd986357mr20177834plg.34.1701378708231; Thu, 30 Nov 2023 13:11:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701378708; cv=none; d=google.com; s=arc-20160816; b=zWdQ/mr2CbByL3KPrz/jQs0DDg5tccgne6dyceifAgvIAaoebZTFn30eErK2e66NZE UiiLOxMqVziMxQFsAWTukndxcrp8mZ8OpgxKsULCV8O4JHAJYfD/tlB9pezDniFRj/E/ mDN3xvEBXjDOdsFoLVXlpMpCsKiu4qioyg10qKf3qp1pireOQ2in9aj61vs6XT+CuAH4 MPa7Edq5fSCx8YrZOWc8Jg9daOarQ1trr7KYn3tXhjJCLc98R2vyAjTdOf+i1jSkFxl0 uu8ChjCilRcn+mxlb9iFi6FzlmdA3ldn96vs/twiZ9alNhGmFf6LgStizYVplotyt9de sM1w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=PSwK/iIUBtKeopk8fKtKKE8DudDA2CgZ8PHsMY6XyUg=; fh=/msuP6Ju3fKK8u2JD1u9DcZxtDGkWzSNk17W+K8U6iE=; b=RsAKvJUmWXVyrGVno/w0i6gCS6xDcvIt36LDDXriR3a1Su2N1nF5PX0KyxQ978euij aiqHrnpfsZEYG8lqlzKvU8qm4JHLawi+x6NuE7SLrZHGLCBBCVGsP8TqVZbLk9055juI svTl7mpBRGhdTPaEXRDzTQn7+fBqUsLsR9ONJ2/7/oIfL/GeW94Rw7+d1h+TU1tEEFCG gIoCVzXf979lrMjx0hSYiEAbzMmn1jMHdRppmiCE8/ptjSFusSClkHMlanEa4AxEewqa q6qpGEIz2b06gJtq0UKjtD9SS+dlRztrOU5XesyZc9P7PgkrBzVB90dyBslesUTdJo2V q+oA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=OuulLBd2; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from pete.vger.email (pete.vger.email. [23.128.96.36]) by mx.google.com with ESMTPS id h18-20020a170902f55200b001c9cc243868si2100813plf.618.2023.11.30.13.11.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Nov 2023 13:11:48 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) client-ip=23.128.96.36; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=OuulLBd2; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by pete.vger.email (Postfix) with ESMTP id AE7078022EB9; Thu, 30 Nov 2023 13:11:45 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230035AbjK3VL1 (ORCPT + 99 others); Thu, 30 Nov 2023 16:11:27 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55674 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229645AbjK3VL0 (ORCPT ); Thu, 30 Nov 2023 16:11:26 -0500 Received: from mail-wm1-x333.google.com (mail-wm1-x333.google.com [IPv6:2a00:1450:4864:20::333]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 31C34133 for ; Thu, 30 Nov 2023 13:11:32 -0800 (PST) Received: by mail-wm1-x333.google.com with SMTP id 5b1f17b1804b1-40b51e26a7aso3825e9.1 for ; Thu, 30 Nov 2023 13:11:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1701378690; x=1701983490; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=PSwK/iIUBtKeopk8fKtKKE8DudDA2CgZ8PHsMY6XyUg=; b=OuulLBd22c1LkpUfq468A9Oh2ANqHNxPmuIL6I88Wt89kDqxNYpp7Xbw2jnbyD3aPo TJtZXBeBmDQVVAmQzr6eWc2IziV6wUx/QhnbBMqQljgG3/qFmwBvP3Rkgpuz9eu6dOUE EF5NNDsxUJvDXN3zxu4BOMfwRjgc3+EuQVBuvo+xgbff+wP3RqjD1aosUkj6JJnSHqCu q76Ol5XhRODBHc5FulJlmYFWwEPzPGwZuNOU/Ml92/OBluc4/8KAKreWpIEgxUlxQxQt GwLqoha5nrYYMv92ErBMETyH5TtFa15he93nJq0SORwLBxHv3FFFtBCwysSfyRgclDYg yttQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701378690; x=1701983490; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=PSwK/iIUBtKeopk8fKtKKE8DudDA2CgZ8PHsMY6XyUg=; b=tyybmnQT7EjAc1WlzYlTpcwVCZuXNsZ5N7eunL0y+atMuSoH56HswrMAlcaWBD6Ch1 txMcvkSjACOU3hp2yv6dhy/JwwZMx7mWXZXxfVxCyrvsKTBb3hO6aAJ2ta1irmdY0CA4 vkqpv3XWfgB275AVtz02J4prtVvFwtkoZxY3zd3yIC/MuVU266PeARSjBpHIyNJlu4OP rfPurxGfDpXbIRpaD/jgLqqdRP9ejdLWfzdsK4/WX6pJ8kNJEe17AaLT9AFUpV7cfmqv YL+NlGNkXq45hqchVM4MPM+iUICIvTUaCxSScH2opwK5HxqdnqmI2utF+gGSg1SmzvVr eYZA== X-Gm-Message-State: AOJu0Yyx+ocWIRnDDS/3hwzy2QHrhEXGcajM6HSf/4Wro0jj6UBaOFDt 05PF+pLYqZNX0Vijgh+4zTI9uOl6PDOuQIFCGc3qRw== X-Received: by 2002:a05:600c:1d81:b0:40b:3d89:ba70 with SMTP id p1-20020a05600c1d8100b0040b3d89ba70mr15422wms.7.1701378690559; Thu, 30 Nov 2023 13:11:30 -0800 (PST) MIME-Version: 1.0 References: <20231030104732.241339-1-rf@opensource.cirrus.com> In-Reply-To: <20231030104732.241339-1-rf@opensource.cirrus.com> From: Rae Moar Date: Thu, 30 Nov 2023 16:11:18 -0500 Message-ID: Subject: Re: [PATCH v2 RESEND] kunit: debugfs: Handle errors from alloc_string_stream() To: Richard Fitzgerald Cc: brendan.higgins@linux.dev, davidgow@google.com, linux-kselftest@vger.kernel.org, kunit-dev@googlegroups.com, linux-kernel@vger.kernel.org, patches@opensource.cirrus.com, Dan Carpenter Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-8.4 required=5.0 tests=DKIMWL_WL_MED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE, USER_IN_DEF_DKIM_WL autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on pete.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 (pete.vger.email [0.0.0.0]); Thu, 30 Nov 2023 13:11:45 -0800 (PST) On Mon, Oct 30, 2023 at 6:47=E2=80=AFAM Richard Fitzgerald wrote: > > In kunit_debugfs_create_suite() give up and skip creating the debugfs > file if any of the alloc_string_stream() calls return an error or NULL. > Only put a value in the log pointer of kunit_suite and kunit_test if it > is a valid pointer to a log. > > This prevents the potential invalid dereference reported by smatch: > > lib/kunit/debugfs.c:115 kunit_debugfs_create_suite() error: 'suite->log' > dereferencing possible ERR_PTR() > lib/kunit/debugfs.c:119 kunit_debugfs_create_suite() error: 'test_case->= log' > dereferencing possible ERR_PTR() Hello! Thanks for sending the re-sends of these patches! This patch also looks good to me! I have one comment below but I would still be happy with the patch as is. Reviewed-by: Rae Moar Thanks! -Rae > > Signed-off-by: Richard Fitzgerald > Reported-by: Dan Carpenter > Fixes: 05e2006ce493 ("kunit: Use string_stream for test log") > --- > lib/kunit/debugfs.c | 30 +++++++++++++++++++++++++----- > 1 file changed, 25 insertions(+), 5 deletions(-) > > diff --git a/lib/kunit/debugfs.c b/lib/kunit/debugfs.c > index 270d185737e6..9d167adfa746 100644 > --- a/lib/kunit/debugfs.c > +++ b/lib/kunit/debugfs.c > @@ -109,14 +109,28 @@ static const struct file_operations debugfs_results= _fops =3D { > void kunit_debugfs_create_suite(struct kunit_suite *suite) > { > struct kunit_case *test_case; > + struct string_stream *stream; > > - /* Allocate logs before creating debugfs representation. */ > - suite->log =3D alloc_string_stream(GFP_KERNEL); > - string_stream_set_append_newlines(suite->log, true); > + /* > + * Allocate logs before creating debugfs representation. > + * The suite->log and test_case->log pointer are expected to be N= ULL > + * if there isn't a log, so only set it if the log stream was cre= ated > + * successfully. > + */ I like this new comment. Thanks! > + stream =3D alloc_string_stream(GFP_KERNEL); > + if (IS_ERR_OR_NULL(stream)) In response to Dan Carpenter's comment from the last version, I see the benefits of changing IS_ERR_OR_NULL() to IS_ERR() instead because "stream" will not be NULL. This would then also be the same as the check in kunit_alloc_string_stream. However, I also see the benefit of checking for NULL just in case anyways. I'm overall happy with either solution but just wanted to bring this up. > + return; > + > + string_stream_set_append_newlines(stream, true); > + suite->log =3D stream; > > kunit_suite_for_each_test_case(suite, test_case) { > - test_case->log =3D alloc_string_stream(GFP_KERNEL); > - string_stream_set_append_newlines(test_case->log, true); > + stream =3D alloc_string_stream(GFP_KERNEL); > + if (IS_ERR_OR_NULL(stream)) > + goto err; > + > + string_stream_set_append_newlines(stream, true); > + test_case->log =3D stream; > } > > suite->debugfs =3D debugfs_create_dir(suite->name, debugfs_rootdi= r); > @@ -124,6 +138,12 @@ void kunit_debugfs_create_suite(struct kunit_suite *= suite) > debugfs_create_file(KUNIT_DEBUGFS_RESULTS, S_IFREG | 0444, > suite->debugfs, > suite, &debugfs_results_fops); > + return; > + > +err: > + string_stream_destroy(suite->log); > + kunit_suite_for_each_test_case(suite, test_case) > + string_stream_destroy(test_case->log); > } > > void kunit_debugfs_destroy_suite(struct kunit_suite *suite) > -- > 2.30.2 >