Received: by 2002:a05:6a10:5594:0:0:0:0 with SMTP id ee20csp471688pxb; Mon, 25 Apr 2022 14:09:30 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxTujq4YdVwyV9O05XV2geTS97Hlk27JI6Prwfg7bS1yxOhK8ZU1izLqxhg42u1mmBHgd1b X-Received: by 2002:a17:90b:4d08:b0:1ce:8d09:1c58 with SMTP id mw8-20020a17090b4d0800b001ce8d091c58mr22995982pjb.168.1650920969679; Mon, 25 Apr 2022 14:09:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1650920969; cv=none; d=google.com; s=arc-20160816; b=naDE3loUC3AssqozADMD5m3iFVmpep5F9/INboSIUbemF0Mhczn8O35taf7+Kt5q2e OeVsKi/L5k9nyymmVVjvRWyCw3b8a7T/O2lXKtmcW9L+Bf+jcNp2PQwvRAo4L8gR4mdC /q5AXY7oXex4aAiA18xguo2IV/8gcrFve77x2FSUQcaCX5+wr5psv7nOlyQ6O/y9WOtV vQJwESKrCvZICNhENP3pd9HcSDakalR1OAYebJbdaVKLSupzec2JF434hQWKTjFhhZIk jB9eJdmsP2iNyXoAC0UKL3/ln6SUEu1+R57cSPmejOh3P1zcLmvByDsMhhne3+X5ouZ6 wF7Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject:dkim-signature; bh=KRYSOrgaeJ2D4S/Wx7GywXi3KDyCDXqWNNYrYsjMpyU=; b=MUGJw6eOkDSJU++PKRt/YeVmWYRy407Wm9p3avAj3iyyn0myAdF+uA3h3fE07gD2dF nkPn9GMSfSyf9vUamBKQAQsrV34xiDaAqxfT0f1e6CQWrbLB6iiWDaiRcYQVwTVTay4d Y+R8vzPFC9Ylg8Vul50L2S5TxEwbP7a6qzkLH0EwWSyfXb1DXqDuMPm7gA9klSToPnzS mIrwQucZMLk8/PduFtpqqGxSO4TPxaVRNqn6Ef7phUmkXs8DABIEBx/XR5/7w/6BQKtw Vfa6K2c0YRmUSmKJsnJKz4iL4UAaKY7qdWDmiiWTM2iGK4Ro7ZhAbDc/Nlnss5RvHirP KLIg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=google header.b="a6Tudt/F"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id r18-20020a170902ea5200b00158e03cfca2si16634734plg.255.2022.04.25.14.09.12; Mon, 25 Apr 2022 14:09:29 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=google header.b="a6Tudt/F"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243021AbiDYPyX (ORCPT + 99 others); Mon, 25 Apr 2022 11:54:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48506 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241638AbiDYPyW (ORCPT ); Mon, 25 Apr 2022 11:54:22 -0400 Received: from mail-io1-xd30.google.com (mail-io1-xd30.google.com [IPv6:2607:f8b0:4864:20::d30]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 26D653A5CB for ; Mon, 25 Apr 2022 08:51:18 -0700 (PDT) Received: by mail-io1-xd30.google.com with SMTP id q22so16319017iod.2 for ; Mon, 25 Apr 2022 08:51:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=google; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=KRYSOrgaeJ2D4S/Wx7GywXi3KDyCDXqWNNYrYsjMpyU=; b=a6Tudt/FF4aceLEyf67ZDqeMl/oD+rorEIh9wu4NaBa+KN9uq7+ipS69p9kzfR/otj yThrGkkFG+OzNwE6bjcMjkTgPe6X65RjUzbfj5jsh/xq7SprTpJYlyJ/P+eZSSzGlA+R 3rEQpLJx9dIrpizhRymVDP1HswnMdVjv8WuJI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=KRYSOrgaeJ2D4S/Wx7GywXi3KDyCDXqWNNYrYsjMpyU=; b=0OGXdsmQvM/Lg6FzANs5p5Lv9ZTdoTogyiU48td+hHreDMLxUEk3Iss8Fw9w0ZMVyN LWv+fhu8b4BCsJjzXIg29VDwmKrSFol+LotlucWSsY8cYqWLhycJAZlJtidu9l0s0fMs RqHKZGj7C+XUQmWugH/YSRS0Q6zjHrhgLKg3G1lnZY9wX/6sRO/wqrc/3cmdw4tOJKfJ Gra1ucYFYg355iYM3A4sooidUvR+tihn3s7YzZNPmV4G8cwHQAz2BoAVNo+cUukuaf9Q rT3K8eR3Xey2EYA9TvQHYWoMa0WvjiKbDTxlP7VOsLqQzYXisl6UwcoN4FLFU26jSA/s /SUQ== X-Gm-Message-State: AOAM5308zOHpZaAqHBOUbPofHKDu+PqKQUd1XKKz/Sxgto+xpnlZmMvf eSiTbXNpg4RJqnsnR7rFxVSL0w== X-Received: by 2002:a5d:9318:0:b0:649:a18:dab8 with SMTP id l24-20020a5d9318000000b006490a18dab8mr7829255ion.96.1650901877580; Mon, 25 Apr 2022 08:51:17 -0700 (PDT) Received: from [192.168.1.128] ([71.205.29.0]) by smtp.gmail.com with ESMTPSA id j12-20020a6b310c000000b0065744ce0180sm7683070ioa.8.2022.04.25.08.51.16 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 25 Apr 2022 08:51:17 -0700 (PDT) Subject: Re: [PATCH] selftests/resctrl: Fix null pointer dereference on open failed To: Colin Ian King , Fenghua Yu , Reinette Chatre , Shuah Khan , Babu Moger , Sai Praneeth Prakhya , linux-kselftest@vger.kernel.org Cc: kernel-janitors@vger.kernel.org, linux-kernel@vger.kernel.org, Shuah Khan References: <20220424211536.1373878-1-colin.i.king@gmail.com> From: Shuah Khan Message-ID: <04a35a47-d83a-67a1-5ed4-ba314c6e1ecf@linuxfoundation.org> Date: Mon, 25 Apr 2022 09:51:16 -0600 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.8.1 MIME-Version: 1.0 In-Reply-To: <20220424211536.1373878-1-colin.i.king@gmail.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-4.5 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS autolearn=ham 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 On 4/24/22 3:15 PM, Colin Ian King wrote: > Currently if opening /dev/null fails to open then file pointer fp > is null and further access to fp via fprintf will cause a null > pointer dereference. Fix this by returning a negative error value > when a null fp is detected. > How did you find this problem and how can it be reproduced? Is there a case where test fails to open "/dev/null"? > Fixes: a2561b12fe39 ("selftests/resctrl: Add built in benchmark") > Signed-off-by: Colin Ian King > --- > tools/testing/selftests/resctrl/fill_buf.c | 4 +++- > 1 file changed, 3 insertions(+), 1 deletion(-) > > diff --git a/tools/testing/selftests/resctrl/fill_buf.c b/tools/testing/selftests/resctrl/fill_buf.c > index 51e5cf22632f..56ccbeae0638 100644 > --- a/tools/testing/selftests/resctrl/fill_buf.c > +++ b/tools/testing/selftests/resctrl/fill_buf.c > @@ -121,8 +121,10 @@ static int fill_cache_read(unsigned char *start_ptr, unsigned char *end_ptr, > > /* Consume read result so that reading memory is not optimized out. */ > fp = fopen("/dev/null", "w"); > - if (!fp) > + if (!fp) { > perror("Unable to write to /dev/null"); > + return -1; > + } > fprintf(fp, "Sum: %d ", ret); > fclose(fp); > > thanks, -- Shuah