Received: by 2002:a05:7412:2a8c:b0:e2:908c:2ebd with SMTP id u12csp3013074rdh; Wed, 27 Sep 2023 22:56:24 -0700 (PDT) X-Google-Smtp-Source: AGHT+IElOsQreL3MPAJjFNKJirCsn8XtFuhKSpndsYM5H8ktTUiAfVrOb4X7+oEpQayUoDp3IDtS X-Received: by 2002:a05:6a00:1817:b0:693:3851:bd98 with SMTP id y23-20020a056a00181700b006933851bd98mr307451pfa.2.1695880584384; Wed, 27 Sep 2023 22:56:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695880584; cv=none; d=google.com; s=arc-20160816; b=pdYvpbRQyKVUDPftN5jYvkuCDErWeiuSR1o7KEdWTR7GelA9Agt9QVAq7Jr401Fi2u HnbZZ4o6d8IrQz0ZbWMsD+ybo/VTDI17SJQTr4pkNMBG8x7vHXF5ljA3lXa3bBwLqePi BwmgKlBE4MVMl4t8nu2oYdTAFpJ4N6NAIlNNIsiRXPOdzD8aGEvQOOnMIy2rd/KmY5+q SkmxIEVkO8VjIOf6IDr47gqy6XyFqfSnE2Ez2eVX4jDkV8FtPYJwXTjRI82LoSF8cgbD Mwi7pWaEBPUyuH2uYZfMKfjqOYKgrfAsV+kF7KiJKwoAGCjcnu12ukgH22aS3H4rSxOK pKOA== 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=IiWv8zF03DQVTTRi4wE0QRJ+TeCqVzE2qQ9Nguz4Rx0=; fh=u7T/nVankybmnNJ9ku8daRs/ogAZq1DGEBDJZvCANJw=; b=StRPvpixfCjD/XyLFsOhigLgqJVLJAzK4sB+mF4VJTGlIwkOZPmXoyNm9I6zavJDq4 Vqyhti4kD7M/7jBMR3DPT6LL1zHIvobdi30XKgV1pS91yPe8AdY1iicdbnso84V37+FZ 0sorTtheEJ3yKWhJMfIgfQa/XnlexueNW1LzdIsPIOtMxBd5lnszwOcTxemn0nMfrL0r WtzCnJeJVg9LI/HbbdidaRS6xiBC99RTFgPBlKpUibaAfYNYsTnIXGagUw+VkOLYNuUu U4AN0BAIyxw8zpDGkSAMpIz+uoxHShaKfevMiLVYm0U5HyMzFqSFUcszqi/Nf5zWsdCY Lqhg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=nHwkXiVt; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 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 snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id y193-20020a638aca000000b00578ca751ddbsi17528900pgd.328.2023.09.27.22.56.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Sep 2023 22:56:24 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=nHwkXiVt; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 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 snail.vger.email (Postfix) with ESMTP id 9A704806884D; Wed, 27 Sep 2023 13:46:17 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229833AbjI0UqP (ORCPT + 99 others); Wed, 27 Sep 2023 16:46:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39168 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229561AbjI0UqN (ORCPT ); Wed, 27 Sep 2023 16:46:13 -0400 Received: from mail-wm1-x334.google.com (mail-wm1-x334.google.com [IPv6:2a00:1450:4864:20::334]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D4617126 for ; Wed, 27 Sep 2023 13:46:10 -0700 (PDT) Received: by mail-wm1-x334.google.com with SMTP id 5b1f17b1804b1-405459d9a96so36305e9.0 for ; Wed, 27 Sep 2023 13:46:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1695847569; x=1696452369; 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=IiWv8zF03DQVTTRi4wE0QRJ+TeCqVzE2qQ9Nguz4Rx0=; b=nHwkXiVts9TyH0GlK8Y/09+6sz1GexZVW6cizDexxhd8PnZI5JdG2PWIoqQvhi1V9D Ph88qt1ahrATqtBXyDMPAIaqgRIOGPyZt2GUvY7JjQyH/rGz2uZ20+/QovWo8YmbmmnY aBQmO+IxpKp5x55VPfWybG/xeksDRkDvvdxjbh5CXDSgIHqkgAArcqYi8rTaRQcCCUFT CkBxDU137sZvWurP7F7+KK+DPt+s3YsYjJmq5oC7yib1XTAeF18lVQRZeprPi2aYjx0F MD79gsnOLT9xkHfW9E7V0HV+AOYByWyGDFknePeRi6jQ5czQ6gCAk7nuoJTOkYaP8ER6 nCuQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695847569; x=1696452369; 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=IiWv8zF03DQVTTRi4wE0QRJ+TeCqVzE2qQ9Nguz4Rx0=; b=I256JLqskk2BaxzwW0GHa4oqStf0Fo+FStPOKUa4arImbjZRAOKLl/1j+xffMs6DRk fXCJ3dcrtbI6lrmT/ghEHVCX1Zp1Bc93A80lSvXntjLDC5yt7fMSYdLzKKoZcimWQKTF r0Ups7znZ3vGQgLwGL0a3oYFQS7ITEVlr2XkGoQmpwKquLp+HpdtH3sMJo34RItUfrjt eOB5Pf/FLwGbCTe9q5rwimeBCktYjmDSJJtE/QwnP13Lws2JZg85CzSggdg+5kF9s9Mj ghuervuzzsybAi7Q5grreIx6rHvInW0yrGW3POjh74S1jV560W2G2A7PJ4fBKyQAVjnS 58rw== X-Gm-Message-State: AOJu0Yz33HXGlAZZ99iJAF7bxfdTlFi9ZgPnKCUarhB5JA+jej9HDJf5 Q8OznxK/66S1IQVs8hCO9NVQA92Ku7xun0h8Llgm6FUSljHrOAe1+EJW4w== X-Received: by 2002:a05:600c:1d9d:b0:3f6:f4b:d4a6 with SMTP id p29-20020a05600c1d9d00b003f60f4bd4a6mr252199wms.7.1695847569143; Wed, 27 Sep 2023 13:46:09 -0700 (PDT) MIME-Version: 1.0 References: <20230927165058.29484-1-rf@opensource.cirrus.com> In-Reply-To: <20230927165058.29484-1-rf@opensource.cirrus.com> From: Rae Moar Date: Wed, 27 Sep 2023 16:45:57 -0400 Message-ID: Subject: Re: [PATCH] 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, Dan Carpenter Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-17.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS, USER_IN_DEF_DKIM_WL,USER_IN_DEF_SPF_WL autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net 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 (snail.vger.email [0.0.0.0]); Wed, 27 Sep 2023 13:46:17 -0700 (PDT) On Wed, Sep 27, 2023 at 12:51=E2=80=AFPM 'Richard Fitzgerald' via KUnit Development 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() > > Signed-off-by: Richard Fitzgerald > Reported-by: Dan Carpenter > Fixes: 05e2006ce493 ("kunit: Use string_stream for test log") Hi! I've tested this and this all looks good to me. Reviewed-by: Rae Moar Thanks! Rae > --- > lib/kunit/debugfs.c | 29 ++++++++++++++++++++++++----- > 1 file changed, 24 insertions(+), 5 deletions(-) > > diff --git a/lib/kunit/debugfs.c b/lib/kunit/debugfs.c > index 270d185737e6..73075ca6e88c 100644 > --- a/lib/kunit/debugfs.c > +++ b/lib/kunit/debugfs.c > @@ -109,14 +109,27 @@ 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 log pointer must be NULL if there isn't a log so only > + * set it if the log stream was created successfully. > + */ > + stream =3D alloc_string_stream(GFP_KERNEL); > + if (IS_ERR_OR_NULL(stream)) > + goto err; > + > + 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 +137,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 > > -- > You received this message because you are subscribed to the Google Groups= "KUnit Development" group. > To unsubscribe from this group and stop receiving emails from it, send an= email to kunit-dev+unsubscribe@googlegroups.com. > To view this discussion on the web visit https://groups.google.com/d/msgi= d/kunit-dev/20230927165058.29484-1-rf%40opensource.cirrus.com.