Received: by 2002:a05:6a10:d5a5:0:0:0:0 with SMTP id gn37csp4075470pxb; Mon, 4 Oct 2021 16:54:34 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzFErbjbEu/hXX0pb9G5J45ulJjYrbW9Fy5vp6oNecJmN2+CthlzEfbAAvo+MTcm6vemElv X-Received: by 2002:a17:906:bc43:: with SMTP id s3mr17288188ejv.46.1633391674442; Mon, 04 Oct 2021 16:54:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1633391674; cv=none; d=google.com; s=arc-20160816; b=asapUXp4yffrUZz7bWue/PCflLw06cc/3LrGfDGrzbvA6NG21euDp9rUDaYxEgoq1e YH5ncSJc1Z1zk75Odogpg7HCiiCdw7/08Yuk0Q8IoBg3b90y4cOHZM/ryofzSz63kT5Y qfFrDvm55qy4kxHtGvpyVK31+Fcw7LtFyTXia0DV6wpKTAsxOd3nFF0Yr6Z+xf5qSM6G sTpcnAhEKBvh9gKOKfDUK6xg7BvJwEMHAx9P5IaPSnRKdDMEBVonrO1OiGkC9M/3774G YByTiW81FmOW1dxSD3sekXtKoD7eg0RTWa6W6+wc/PC6LKrWy9D/b/YT4XkiiFchYZ0I H+MQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=oR9FHMJEaE13BkBpbWUGvIfigwsE0vr7a2ZHshK3wS8=; b=gi6TgN3sW3/Ivqa2ILsVcki+pUTH/Di/voB8JjzuPZZqTdPmjPZzAYYygq0eOCKyKf oov2IksFAsSFcB86TxjAEgG27eSpSCBVzYUHvpzkyrb6UgpwrpuMQ6zwg4qZUnaDI8e9 TUdzdMQv7M7CeLhimE/FbcotB8ZPGIWGOvwQRcNXTW8Wdz375UcxXZz6IyKDj8Mmfj5r Qb2DT+0VBDHbp3sodxBowBYLO3Lsdz05FrFkpHKEqj2L2K5uNt4TY0XHBBWq6rd7puFH DnTnjLRSq3fHZGkWifslULc3BuozlLTbOtPvnjYgOdhQ1bGPcqP33VM/7ZfwqEAklbrE nbvA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=Uoo+1ct0; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id q11si573255edd.253.2021.10.04.16.54.11; Mon, 04 Oct 2021 16:54:34 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=Uoo+1ct0; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233319AbhJDWBA (ORCPT + 99 others); Mon, 4 Oct 2021 18:01:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43178 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234443AbhJDWBA (ORCPT ); Mon, 4 Oct 2021 18:01:00 -0400 Received: from mail-pg1-x52e.google.com (mail-pg1-x52e.google.com [IPv6:2607:f8b0:4864:20::52e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C6895C061749 for ; Mon, 4 Oct 2021 14:59:10 -0700 (PDT) Received: by mail-pg1-x52e.google.com with SMTP id v11so5287662pgb.8 for ; Mon, 04 Oct 2021 14:59:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=oR9FHMJEaE13BkBpbWUGvIfigwsE0vr7a2ZHshK3wS8=; b=Uoo+1ct0QV2Ux4fbTZVkWV8nryL5oetajREzRreulNaUhqlC127gIysHH7lp/i5knd STWX/oNrsWN/HniF6cnQextBItaxCNwuRcpx/leW+XanjTZULZlAs1FdmzN6w1oGLTks XjkB8WL/XqvKW/Hu2cBqEIKC2JRFf+GWKDb+4fy1w94BjAyYTUi9F7X9dDKeM9RpNPHv 8oDAUbv2tcX08n7EstQAwWAjsLm8S5P1VbkOYlcEmBBGcLBIooCZpHd/6G03TqPmJGX+ 8WY2gFAXuya754SoO6LK5JOY9kqfXXHGCMesZ1NCfhngY0kKQfSLeHz9HL+zFEfmIuGV ZJqA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=oR9FHMJEaE13BkBpbWUGvIfigwsE0vr7a2ZHshK3wS8=; b=Zm7yJjDb/d8Vo8pPew2L6Ietr0aqZHXTxv27dG0SJN1ghWQYfasB71IHdBySXmV+T0 uQbuhXksQMub90H+Q4C8e7NSlLxZhGujauhfCSAAxNzZv/xqhAdUHw3t4/S9HWcETTKx 8cMJjmM8lGXXCX8S5mPqCWQiaRzoTZHzwGoCHqesWci8U65ecpdHJie8DtKGJb3s8/Pp Q28G1Mp/p2yZVQtIQAf9Wlej/tyMfQLz8RAW7WfOz3eVU+IY1yXSYExKEOlb7qH8eS4i rJxEwsTdNYMwY5IR+OfmSSphHh4J/rYiKWwc1OW6uSSrbi6V45Fz/26rb1xo/3cmN9ds KSLQ== X-Gm-Message-State: AOAM531FkrXw8dac9EsjT63UQ+iRqxolZqJqHTV9/StzCuP6UPN1CiH5 tvxe/wcDOn5+0bXM/Ph65yvJxJ9TT8zYnYnAfbpz5w== X-Received: by 2002:a65:6658:: with SMTP id z24mr13092905pgv.266.1633384750068; Mon, 04 Oct 2021 14:59:10 -0700 (PDT) MIME-Version: 1.0 References: <20211002013635.2076371-1-dlatypov@google.com> In-Reply-To: <20211002013635.2076371-1-dlatypov@google.com> From: Brendan Higgins Date: Mon, 4 Oct 2021 14:58:59 -0700 Message-ID: Subject: Re: [PATCH] kunit: fix too small allocation when using suite-only kunit.filter_glob To: Daniel Latypov Cc: davidgow@google.com, linux-kernel@vger.kernel.org, kunit-dev@googlegroups.com, linux-kselftest@vger.kernel.org, skhan@linuxfoundation.org, kernel test robot Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Oct 1, 2021 at 6:36 PM Daniel Latypov wrote: > > When a user filters by a suite and not a test, e.g. > $ ./tools/testing/kunit/kunit.py run 'suite_name' > > it hits this code > const int len = strlen(filter_glob); > ... > parsed->suite_glob = kmalloc(len, GFP_KERNEL); > which fails to allocate space for the terminating NULL. > > Somehow, it seems like we can't easily reproduce this under UML, so the > existing `parse_filter_test()` didn't catch this. > > Fix this by allocating `len + 1` and switch to kzalloc() just to be a > bit more defensive. We're only going to run this code once per kernel > boot, and it should never be very long. > > Also update the unit tests to be a bit more cautious. > This bug showed up as a NULL pointer dereference here: > > KUNIT_EXPECT_STREQ(test, (const char *)filtered.start[0][0]->name, "suite0"); > `filtered.start[0][0]` was NULL, and `name` is at offset 0 in the struct, > so `...->name` was also NULL. > > Fixes: 3b29021ddd10 ("kunit: tool: allow filtering test cases via glob") > Reported-by: kernel test robot > Signed-off-by: Daniel Latypov Acked-by: Brendan Higgins