Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp3196788pxb; Mon, 9 Nov 2020 05:21:58 -0800 (PST) X-Google-Smtp-Source: ABdhPJzBbYahAa0/8EIPpO6byKj6/DHzz/IyrGbVlaJbdgDzFOHiUu5dTQBf2kHQddQvdxSoosQO X-Received: by 2002:a17:906:6a57:: with SMTP id n23mr15848445ejs.315.1604928117832; Mon, 09 Nov 2020 05:21:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1604928117; cv=none; d=google.com; s=arc-20160816; b=e0FwFN/Lle3rYtB1ZEu24wpky64UT4pK2XePcZo+kb6JJZSitmUYCl7LZpy2EpPDhT jdUb9ufYxVgLw6gTN5CfryGNnXZfN2+5Mrkx8t1xlxWbYZxj3m70tiiIWLZ0VuaE/87N 0eIDpy75Z4XGKwZIpjvsHa8nwv3NV8ZhPfvDUWEuXCYx6UkcXMEu1A555SOAhFO/JbOk 45w+WtMtSdHI83aZnGmIwOCX9gab7wbZ82w1iVrtHmpvZ5SPXJK6iIiEHjTyY/mqi0P+ 2eT7cLlsv6IFFDEpKdQ8ODzwKzdtYJgmbYSOZJvg47JBV8uWqHnXePORxm7w6JDrlE2m eIeA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=P7Db5eMg68LkHl7F7aNydWVG7Eg/rNzChMuP6N7xTV8=; b=OfsqKp+lADXp/y9lQKBfONwZEgtXPWoGY726ER1qctOlxLFSTjpA1SSA+9BKjwUIt/ SOZW8L3Ledlq1mDf5NbxYaowBlkxjvWLDpTUIASQ6+vNVP/6s8wusuF880XK3dPyBKWQ 81UNMS9cnZjPaevpcM9YvqGBYhOT+lbELW2F2DR32uLFA0mkIe8zxajuEFvwBkDET+hZ WGBRuMX4ER1BRpFUfAlyMcUAPv054gsSwYcmZ7mUapkqZK/x7xmoLuFTL4UlqCCDkeJv g6VZjY3U7MQaOA8+O5Gg2S6bqMLi6hvGqx+tspP8/mGGq5AYlnsgRdEdNnxgEjSgz2a9 njWQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=mZk8NYjS; 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=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id q3si7103741edv.85.2020.11.09.05.21.34; Mon, 09 Nov 2020 05:21:57 -0800 (PST) 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=@kernel.org header.s=default header.b=mZk8NYjS; 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=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732554AbgKINUV (ORCPT + 99 others); Mon, 9 Nov 2020 08:20:21 -0500 Received: from mail.kernel.org ([198.145.29.99]:47912 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387925AbgKINUT (ORCPT ); Mon, 9 Nov 2020 08:20:19 -0500 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 6006420731; Mon, 9 Nov 2020 13:20:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1604928019; bh=Sg5nBRuNwWbX4eBpaGXlIk1GL/jH5nUeaGsE0BNPZKQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=mZk8NYjShA3Ggm5ATpoxXrbW4wPfrTBsotX110ZV2zMMJd/Z8ZkUKT0UrjGjD4+tC NRdLmfkzLd8zICnsYttcdOA1D0/ZhDJD2x21cnO/vxiHzmoVQKFZ+9RRVwy8svA+1M x5x/MBby6eu/GxGNXkT5h6TZKSZ/94J86afEHlKI= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Qiujun Huang , "Steven Rostedt (VMware)" Subject: [PATCH 5.9 069/133] tracing: Fix out of bounds write in get_trace_buf Date: Mon, 9 Nov 2020 13:55:31 +0100 Message-Id: <20201109125034.053522275@linuxfoundation.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201109125030.706496283@linuxfoundation.org> References: <20201109125030.706496283@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: Qiujun Huang commit c1acb4ac1a892cf08d27efcb964ad281728b0545 upstream. The nesting count of trace_printk allows for 4 levels of nesting. The nesting counter starts at zero and is incremented before being used to retrieve the current context's buffer. But the index to the buffer uses the nesting counter after it was incremented, and not its original number, which in needs to do. Link: https://lkml.kernel.org/r/20201029161905.4269-1-hqjagain@gmail.com Cc: stable@vger.kernel.org Fixes: 3d9622c12c887 ("tracing: Add barrier to trace_printk() buffer nesting modification") Signed-off-by: Qiujun Huang Signed-off-by: Steven Rostedt (VMware) Signed-off-by: Greg Kroah-Hartman --- kernel/trace/trace.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) --- a/kernel/trace/trace.c +++ b/kernel/trace/trace.c @@ -3114,7 +3114,7 @@ static char *get_trace_buf(void) /* Interrupts must see nesting incremented before we use the buffer */ barrier(); - return &buffer->buffer[buffer->nesting][0]; + return &buffer->buffer[buffer->nesting - 1][0]; } static void put_trace_buf(void)