Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp4370968imw; Tue, 19 Jul 2022 05:31:36 -0700 (PDT) X-Google-Smtp-Source: AGRyM1uKs41uqdoObG9zZ1F0m1po3I/1/CKaUWl4vIx7I7lsJXTpNoP1QcTeTdV6Ti2DDav7d27/ X-Received: by 2002:a17:906:38ca:b0:722:e836:1d85 with SMTP id r10-20020a17090638ca00b00722e8361d85mr30405642ejd.194.1658233895980; Tue, 19 Jul 2022 05:31:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658233895; cv=none; d=google.com; s=arc-20160816; b=W/GoLV98w04N4Q5LK7m3P07F5JC6NBOuGMvshwjTigKGAm7ugh1WjTwlpeyJUziARy aYx/AoR6HuIHOZxgO6DnFMYCPrBAZdMUkeDUuYkqQSbpCCQyzuF+5By6PryQAow7J5ox Snk+Z1BaJ//aAdKj/UTyvrF4uJ0hSRSBtp1WZLYWxFkvTQRd8DV1TQ8lrUzHgt/vxUPo h5TxL7T7uH4Ai2lgHP1PpeBaIjKZKZseFbezUMzViUFFn3FEWfR/9XVndlgYXZZZ2+/0 CyKyGB2My8nhtMQl7DWifOsNV58wMqH4i5j9HP9j1x9Rly0fcD+K5Bg3sj12UllrHPwU bpfA== 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=In6GDXzCUEUORXeX6j3v5CKi+mzt/n9a95i2Zz00PMw=; b=eGPrWGzIfObMDFBEtzQKPdTPWRDlNJwQ9Oa4O2S/9tctwbrjxWKxZ1qk2/hQTNTUfR iH014BWSop3YYqTIZ8pY4+BORBVEJkVKt5NmTO8Dkqi4TbglHJZW/k9M+Is122k8q36l yxkimBaeGZLJ6+tknc36ujA6iZkqnwOCmVae+oa3G3QrL9MHxuDdcGbxzG6bpYHmA0SE WkRLUN64hlV9MSTfQPKbDyolC1TDOEFLwQKv7tPQZuuAX5KuCUeIKIPzGNo+NXJ6ql48 UyHucqvj3U8dQ8sjgY2RjgWfpBQ2IaUT1FVyczMXLPeKNwuFYbE6r9PSE2KFwoqScsBE jD9g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=hieiSK2O; 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 dn7-20020a17090794c700b0072b69650f7esi17636528ejc.719.2022.07.19.05.31.10; Tue, 19 Jul 2022 05:31:35 -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=hieiSK2O; 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 S236579AbiGSLz4 (ORCPT + 99 others); Tue, 19 Jul 2022 07:55:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54306 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236046AbiGSLzr (ORCPT ); Tue, 19 Jul 2022 07:55:47 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 911E82126B; Tue, 19 Jul 2022 04:55:46 -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 dfw.source.kernel.org (Postfix) with ESMTPS id 2846261604; Tue, 19 Jul 2022 11:55:46 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 08285C341C6; Tue, 19 Jul 2022 11:55:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1658231745; bh=WF+JF/DvnZSZ5LUxV1QMZaljY2ecx2pyfyAY8MPY1/c=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=hieiSK2O3dWCybMwycNfluaGn0YM++k39xrWQCajZSJ6izJT/UWVY6WjoTCxHA8/r PpOlEkMSzZ8svVE2qAouhp1DkUMJRx76sb1B5VqPa4o9onf84blZMGE7dnB1UJuaBx Kcu3SxUeACrqwULwgjGK5OXdaa+ZAZegd86P+3gA= 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 4.9 04/28] net: sock: tracing: Fix sock_exceed_buf_limit not to dereference stale pointer Date: Tue, 19 Jul 2022 13:53:42 +0200 Message-Id: <20220719114456.983007516@linuxfoundation.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220719114455.701304968@linuxfoundation.org> References: <20220719114455.701304968@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 @@ -37,7 +37,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) @@ -45,7 +45,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 = prot->sysctl_rmem[0]; __entry->rmem_alloc = atomic_read(&sk->sk_rmem_alloc);