From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH, MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id F028DC838E5 for ; Tue, 27 Oct 2020 15:56:51 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A7134204EF for ; Tue, 27 Oct 2020 15:56:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1603814211; bh=fOABcqOS06c/3a5azTwVXJAhNX2nDHzFYV3Nr3ABGH8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=M8q4/OKYVBkkt83mOht6hUP0lOSy4Nb0QoTlOCl4i8D7jy48Nbxv/8GS2Zi9I4Pf+ zCkqnvfUnrPlBqHr1do9hMYtwY0rFhmNlDzkxBSlic6Gv7W83KS7sBps8rDgFE18WL eFbDGXLx3oSYD8hFSBrqYj4odlgFRDYodB3LezAI= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1803341AbgJ0Pwi (ORCPT ); Tue, 27 Oct 2020 11:52:38 -0400 Received: from mail.kernel.org ([198.145.29.99]:55718 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1800672AbgJ0Pgt (ORCPT ); Tue, 27 Oct 2020 11:36:49 -0400 Received: from localhost (83-86-74-64.cable.dynamic.v4.ziggo.nl [83.86.74.64]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 4B9872064B; Tue, 27 Oct 2020 15:36:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1603813009; bh=fOABcqOS06c/3a5azTwVXJAhNX2nDHzFYV3Nr3ABGH8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=GsbPAjseZ0O2nIBdObhzJ4Vs85UnwoJ637zArjTWjqwafqQefzASKn6K2CsT040/C voxLx6YrQ+3biV/3/+Zw+4zDLL9e54JdBh5qhAXQTfm3D2pTvIyJ/5TgqmKnh2ef91 L9nOczpY+CLfXdRRKLc+H3puddv8OTt5TucPytxM= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Colin Ian King , "Paul E. McKenney" , Sasha Levin Subject: [PATCH 5.9 405/757] refperf: Avoid null pointer dereference when buf fails to allocate Date: Tue, 27 Oct 2020 14:50:55 +0100 Message-Id: <20201027135509.572088475@linuxfoundation.org> X-Mailer: git-send-email 2.29.1 In-Reply-To: <20201027135450.497324313@linuxfoundation.org> References: <20201027135450.497324313@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Colin Ian King [ Upstream commit 58db5785b0d76be4582a32a7900acce88e691d36 ] Currently in the unlikely event that buf fails to be allocated it is dereferenced a few times. Use the errexit flag to determine if buf should be written to to avoid the null pointer dereferences. Addresses-Coverity: ("Dereference after null check") Fixes: f518f154ecef ("refperf: Dynamically allocate experiment-summary output buffer") Signed-off-by: Colin Ian King Signed-off-by: Paul E. McKenney Signed-off-by: Sasha Levin --- kernel/rcu/refscale.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/kernel/rcu/refscale.c b/kernel/rcu/refscale.c index d9291f883b542..952595c678b37 100644 --- a/kernel/rcu/refscale.c +++ b/kernel/rcu/refscale.c @@ -546,9 +546,11 @@ static int main_func(void *arg) // Print the average of all experiments SCALEOUT("END OF TEST. Calculating average duration per loop (nanoseconds)...\n"); - buf[0] = 0; - strcat(buf, "\n"); - strcat(buf, "Runs\tTime(ns)\n"); + if (!errexit) { + buf[0] = 0; + strcat(buf, "\n"); + strcat(buf, "Runs\tTime(ns)\n"); + } for (exp = 0; exp < nruns; exp++) { u64 avg; -- 2.25.1