Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp3209382pxb; Mon, 9 Nov 2020 05:39:34 -0800 (PST) X-Google-Smtp-Source: ABdhPJy+Y+pU42hpC9WbV2KJRZwWK+tZnF1hEoGRox3Ghtt6BcT/meYYXJWWZyaTjMRVc57qmYmj X-Received: by 2002:a50:bc04:: with SMTP id j4mr14824669edh.316.1604929174574; Mon, 09 Nov 2020 05:39:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1604929174; cv=none; d=google.com; s=arc-20160816; b=w4G4n1wYDNy5r2uO70uLxYoZF0NQA6kbJK1pUFny1bPkJ2Uluc4Jzl+9SMXe05jeNE RCoCY0VaIerAY/nhLFjdKrrznCCwSyTW3vl9WoZdEgb+xq+6aF0sNtj1WgUBbzHSd6Fp X1aHBXPlY7CUywN5HTQ2E4q7uZa4X6VUfNwucz6alPfbOJVI0sSdWOUvPoFCv9SwPjt+ oYfcGWW7sDtzB/MJ1tAL2YILvEoW5VR9SyZAjtmOiFJl2+lw1lC6KVEveOEes+O7XJui w3hU/29JTLbc9MpNPEwU/PECUnyf7MpKdlADrSk7WPy8+V1EdNIUTJRo8OOw/+hOZoE9 GtSw== 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=Tmipp5IdSKDbT5hNIzEFu1SpMBAByRA3Huqcah4S0yY=; b=vJlPGeiJwPFaZ7CBlU23xPOBKniYd7U8TOQcLko6vftfVFyq0FlTj5DO33u6apbpAi E0XhabIEKwc8ph18jgpZMzqQlz2l7pyP5DKluEvPeGVBbErHlzyOHkCdDgZFJCjdWTxa h7t/ZSCD9WK9SMemgUoBSyfdcWDCB6B4tmAsVZqfwd9+z5lNiMXwTb6yud7BEnssrJN9 79JsGUmgH4B4dgpH8jZLrvPg96RCNBx/40RJKeKByxSDNjBhX0c/dNnIzpQNBdBYtWYi VnQy9yv4813LX07GNSMSEZ1fLjHuHxGJ/EC72xBmyta5N06dwkU5FtmKveupiC4fxmQG H/kg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=bbhHnHiK; 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 d12si8283315ejj.33.2020.11.09.05.39.11; Mon, 09 Nov 2020 05:39:34 -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=bbhHnHiK; 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 S1733169AbgKINgs (ORCPT + 99 others); Mon, 9 Nov 2020 08:36:48 -0500 Received: from mail.kernel.org ([198.145.29.99]:57596 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730464AbgKINEn (ORCPT ); Mon, 9 Nov 2020 08:04:43 -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 96E9721D46; Mon, 9 Nov 2020 13:04:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1604927073; bh=Ba8ejmRJaJTHm0BtxP8Zu5VIUwq0Z1XprR6TwG7e3f8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=bbhHnHiKwKlLbdZREeaaxpd2zHdq/6u5QA/vXehctdizd++aLXsbJNxskz+fcsYsB jyVAupyISLQ7jAXgN+i6xWDPhnenvVn7BQ4aw+4JdehALUV+jv3xoUht5HtePF5ExG agEC1iHhKZGKIVnGIE84biyMEKqnA03j4ovI8IrU= 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 4.9 101/117] tracing: Fix out of bounds write in get_trace_buf Date: Mon, 9 Nov 2020 13:55:27 +0100 Message-Id: <20201109125030.496019435@linuxfoundation.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201109125025.630721781@linuxfoundation.org> References: <20201109125025.630721781@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 @@ -2382,7 +2382,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)