Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp4371392imw; Tue, 19 Jul 2022 05:32:00 -0700 (PDT) X-Google-Smtp-Source: AGRyM1vztuQBXIIZks2O/Zw7azbpEZFPADdhTwZhfTLF6Qf/RZF6nK3ozjso8PxKjWD7R8mYWTko X-Received: by 2002:a17:907:67b0:b0:72b:972c:53df with SMTP id qu48-20020a17090767b000b0072b972c53dfmr31521560ejc.37.1658233920308; Tue, 19 Jul 2022 05:32:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658233920; cv=none; d=google.com; s=arc-20160816; b=0VHswtUDcpfxOCw2J/w1Z4edxU2n0cil317UG0+CKOcVpPiP/iL0YgECIopob0fmZ0 gYVPpVk+O2evwqMvI1hQwlm+zZNS352etxLoXNMvC9n6AyMHm03PEwabDjZL666QbNUz MOBaO2SrugGhlPx34zCHPRNd6QltIbAfisB5sbtARJ4QMaUf+O2a8BDgEWVABz30qLQU vlnRdVGVDiSqz/J8ybzZqjCnRmkADLKf+P36nXPws1zXwMTRy+PjGxfksTjUCCGAyEH1 pW8FZHBUkZBv0NRrdevJqeyJfTs+/fIGwbmr8nw3r3Q2D+pTcf+9pFf02NtcoNPpjnyU pThg== 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=lS6ZNGkS/P4QDb6VHyyXgQIuXujrRLtHLx0kR0k26Sc=; b=jj2ESvGwRxQKtkb7HVVHJ0tkPB4BQVGX7Vf6cVFq5q0X0tXRQavi0okK4qlJRuBzmU 8HJxsrcfcOq/+63vfNyPnrkPWW/eqP/B3zwrMj6QirgP/hLLeGTLTYzgZlv0DReJ5VH0 2t+6RVdocKR1/35IdyU2XLz/CKYn4VueXn3sQk94dZRWYOIwcnKQp3xuLK+c59k+QsSm f9LGC+NWNiWZgCKiUJ1IbAuZ9i4OTD3nnkJW61v3VWYfsUCHYzeolXZw4fLcxIBbCsS+ obgS5BF4ynFfXBhqTySqt8TCUcLbntH1a2vro13UuExLxjAsoq4nZG7bkWZfIEFGimYc Cj9Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=MacgMPSj; 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 mp9-20020a1709071b0900b0072f00759bfbsi16893270ejc.634.2022.07.19.05.31.35; Tue, 19 Jul 2022 05:32:00 -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=korg header.b=MacgMPSj; 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 S239261AbiGSMPr (ORCPT + 99 others); Tue, 19 Jul 2022 08:15:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39240 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239172AbiGSMOT (ORCPT ); Tue, 19 Jul 2022 08:14:19 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CB15B1010; Tue, 19 Jul 2022 05:05:22 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id AED31B81B38; Tue, 19 Jul 2022 12:05:03 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1D446C341C6; Tue, 19 Jul 2022 12:05:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1658232302; bh=kPJAsjLpGBb2Q5ipTE7OnPID7nGe121aKEl9He9CuPQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=MacgMPSjZ/XMYwnwS2u8yMlRc60TBzyI75CUbgbKGlA9o/qaKC0uM6VqsAi4BoPL4 WqxtPhpPL+6/iQhoVdZoDloUZz1+d3tg+XPFyl4CSMM0DE6mnGv5k985Zzx56belx5 /p8XgJjCyJlbhNRg3k6oJNhUY0lA86CmBEGiypIo= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, "Steven Rostedt (Google)" , Kuniyuki Iwashima , "David S. Miller" Subject: [PATCH 5.10 011/112] net: sock: tracing: Fix sock_exceed_buf_limit not to dereference stale pointer Date: Tue, 19 Jul 2022 13:53:04 +0200 Message-Id: <20220719114627.095104940@linuxfoundation.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220719114626.156073229@linuxfoundation.org> References: <20220719114626.156073229@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.8 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, 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 From: Steven Rostedt (Google) commit 820b8963adaea34a87abbecb906d1f54c0aabfb7 upstream. The trace event sock_exceed_buf_limit saves the prot->sysctl_mem pointer and then dereferences it in the TP_printk() portion. This is unsafe as the TP_printk() portion is executed at the time the buffer is read. That is, it can be seconds, minutes, days, months, even years later. If the proto is freed, then this dereference will can also lead to a kernel crash. Instead, save the sysctl_mem array into the ring buffer and have the TP_printk() reference that instead. This is the proper and safe way to read pointers in trace events. Link: https://lore.kernel.org/all/20220706052130.16368-12-kuniyu@amazon.com/ Cc: stable@vger.kernel.org Fixes: 3847ce32aea9f ("core: add tracepoints for queueing skb to rcvbuf") Signed-off-by: Steven Rostedt (Google) Acked-by: Kuniyuki Iwashima Signed-off-by: David S. Miller Signed-off-by: Greg Kroah-Hartman --- include/trace/events/sock.h | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) --- a/include/trace/events/sock.h +++ b/include/trace/events/sock.h @@ -98,7 +98,7 @@ TRACE_EVENT(sock_exceed_buf_limit, TP_STRUCT__entry( __array(char, name, 32) - __field(long *, sysctl_mem) + __array(long, sysctl_mem, 3) __field(long, allocated) __field(int, sysctl_rmem) __field(int, rmem_alloc) @@ -110,7 +110,9 @@ TRACE_EVENT(sock_exceed_buf_limit, TP_fast_assign( strncpy(__entry->name, prot->name, 32); - __entry->sysctl_mem = prot->sysctl_mem; + __entry->sysctl_mem[0] = READ_ONCE(prot->sysctl_mem[0]); + __entry->sysctl_mem[1] = READ_ONCE(prot->sysctl_mem[1]); + __entry->sysctl_mem[2] = READ_ONCE(prot->sysctl_mem[2]); __entry->allocated = allocated; __entry->sysctl_rmem = sk_get_rmem0(sk, prot); __entry->rmem_alloc = atomic_read(&sk->sk_rmem_alloc);