From patchwork Tue Jul 11 14:15:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Masami Hiramatsu (Google)" X-Patchwork-Id: 118566 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:a6b2:0:b0:3e4:2afc:c1 with SMTP id c18csp524756vqm; Tue, 11 Jul 2023 07:34:20 -0700 (PDT) X-Google-Smtp-Source: APBJJlGSlBbhD5JQgnFMDyqkhVKqtDYXNqZVK0rb5O4j+/e4GhjB6ZTqjyHaCsSUk1R8Na6ml75i X-Received: by 2002:a17:906:6c87:b0:957:2e48:5657 with SMTP id s7-20020a1709066c8700b009572e485657mr14595049ejr.68.1689086060416; Tue, 11 Jul 2023 07:34:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689086060; cv=none; d=google.com; s=arc-20160816; b=Yw++QB1Krzfe1wqw6EbGZJ32WfbHZD/hKYVyoKqKZant4Cmo02+I4bmLqN4YKBjjnx ZpiUuTBUygXilF/eHmtX2PB2KpL6t3Pb+LruDXm4EWxIurljZU2w8p+KyQxkMTNzpLw6 oHn1UoD8V3hRFbI17ViACsQCU92Ym2O+h5fH17qY+ilEFOL138wEolfYS8MhcecW3ryg DAbF3BHujaQVah05/5I8nchXZf3sT9Cwal3PE911Exo3BVtam9WYnzPNwNUP7mp/pFxN gZb8w1hhicM4YjYwZcpcV8qCwRlF76+/uzVd6iCOU9B66FrjE9CUEs4r0g3TYKeKjWLd KLwg== 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=ELAaMWiZc9h+dU7lS9cL5UHtCJaBJK2f/UmP7iEJY/Y=; fh=hf24JvveL55vCfzfv0agRHDWsuhzZqIeZ7dfs5kcUjQ=; b=mwPT3izsO9YG3YpNW17/JmQC1ujoJTjOo4F8g9EzrIgJ6exCKqrcD+chEQEzEs7/BH PeVl5JvvMdwNOcNy/inn8iUkIVI6/Q+z54zyhAMUHDR8YyOhWcmO0jJTriNR24fRBUMz W0c5UAOSz0ZofZN+aJVExjPe+6Sj7xiL3fMvzxEWRvTUHWu7FoH57Mtkc9sFexpB8Hb5 gY2qCXjKEuC6XWuNEGJFG1yUsZ+J5V3lOnvDE8dVwmkB5kYf5KMde0JSyzT18o4RBL/h sPa55+oKk1wUwfyU5GTRhzTquAxP6vPdFybyEyj9hLuRK4tsb01lGdEPTRzbRTR49+/b Od3A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=jHrQijNu; 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=kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ks20-20020a170906f85400b009931a072599si1883645ejb.454.2023.07.11.07.33.55; Tue, 11 Jul 2023 07:34:20 -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=@kernel.org header.s=k20201202 header.b=jHrQijNu; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233450AbjGKOPk (ORCPT + 99 others); Tue, 11 Jul 2023 10:15:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52660 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233436AbjGKOPf (ORCPT ); Tue, 11 Jul 2023 10:15:35 -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 0083F1705; Tue, 11 Jul 2023 07:15:33 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 8BF106150D; Tue, 11 Jul 2023 14:15:33 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id C2FA8C433C7; Tue, 11 Jul 2023 14:15:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1689084933; bh=77y8W85i7xf9qeyXJXcSDIyy5bcBOPvmg0r6OCuWIr4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=jHrQijNug8+1yMpULTBzLmTy8i0AMW+NL0U/e2Us3ej9u//1v3DYXBC7a4V8tCFRo pzyk4QOXnXIYS7Bbe4mk4QRqcUlMaa0mUxgwgesOQjGgCP+i9LxMUl2QKtlAgxgeZp czdq6gFzuItu72NyNQ8nwMqKroV3rkPQS80FELKMeO1gsrb7mMElll388oU+banh8E ANvyuKqU4cNSmb3D0OBDToFcoi9pIkFOsG/nFvNWs+Knv3eMrV4qXdtYk+lLBoKv4m n+aG6k8FuzW23nRTIHmxPLKrV3lKpqabhjuZeMw+g+dcg9wMepidCyIK/6JluZHKCD EpqRXj++kRvqw== From: "Masami Hiramatsu (Google)" To: Steven Rostedt Cc: Dan Carpenter , linux-trace-kernel@vger.kernel.org, LKML , Masami Hiramatsu Subject: [PATCH v5 1/5] tracing/probes: Fix to avoid double count of the string length on the array Date: Tue, 11 Jul 2023 23:15:29 +0900 Message-Id: <168908492917.123124.15076463491122036025.stgit@devnote2> X-Mailer: git-send-email 2.25.1 In-Reply-To: <168908491977.123124.16583481716284477889.stgit@devnote2> References: <168908491977.123124.16583481716284477889.stgit@devnote2> User-Agent: StGit/0.19 MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE 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 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1771135104897491388 X-GMAIL-MSGID: 1771135104897491388 From: Masami Hiramatsu (Google) If an array is specified with the ustring or symstr, the length of the strings are accumlated on both of 'ret' and 'total', which means the length is double counted. Just set the length to the 'ret' value for avoiding double counting. Reported-by: Dan Carpenter Closes: https://lore.kernel.org/all/8819b154-2ba1-43c3-98a2-cbde20892023@moroto.mountain/ Fixes: 88903c464321 ("tracing/probe: Add ustring type for user-space string") Cc: stable@vger.kernel.org Signed-off-by: Masami Hiramatsu (Google) Reviewed-by: Steven Rostedt (Google) --- kernel/trace/trace_probe_tmpl.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/kernel/trace/trace_probe_tmpl.h b/kernel/trace/trace_probe_tmpl.h index 00707630788d..4735c5cb76fa 100644 --- a/kernel/trace/trace_probe_tmpl.h +++ b/kernel/trace/trace_probe_tmpl.h @@ -156,11 +156,11 @@ process_fetch_insn_bottom(struct fetch_insn *code, unsigned long val, code++; goto array; case FETCH_OP_ST_USTRING: - ret += fetch_store_strlen_user(val + code->offset); + ret = fetch_store_strlen_user(val + code->offset); code++; goto array; case FETCH_OP_ST_SYMSTR: - ret += fetch_store_symstrlen(val + code->offset); + ret = fetch_store_symstrlen(val + code->offset); code++; goto array; default: From patchwork Tue Jul 11 14:15:38 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Masami Hiramatsu (Google)" X-Patchwork-Id: 118562 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:a6b2:0:b0:3e4:2afc:c1 with SMTP id c18csp517471vqm; Tue, 11 Jul 2023 07:22:46 -0700 (PDT) X-Google-Smtp-Source: APBJJlHussN7mMiAtPCf2q7SKsLxqGqr9gLBrn0KjGaf7e7BqEZao3CtkbB6SsMzcAWkcuD2KxzF X-Received: by 2002:a17:906:19:b0:982:82aa:86b1 with SMTP id 25-20020a170906001900b0098282aa86b1mr15321424eja.43.1689085365853; Tue, 11 Jul 2023 07:22:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689085365; cv=none; d=google.com; s=arc-20160816; b=j9C1rS+w8i8KaH/NWKpeAgjQE07Eu9ax56kbqwm+jtBG3HHzn5EpNOGlSUO0FOfVZN vehnTOB9r56XPF8qMjeTfx1p7saXWzs25R1+yZuGbofP0iIUC3I5SXrLPZYvwlpinoJR aG0+E3pJscDbxBObVjSvbwS2F5FtRF4Sqmzlx210zlWMr9J+j3Y97jrfGVyAMHQgCzzP +hwIdOm8pVBqbxBIONsjuO603vzv7DVCeM97q/NcG/3aH/CO3+5NPijfgvKEtzfjqysv SkVEHwVTZGavCQUsHIAgu9zHxUvB6iHW+yzAfT6RE4W4+e6L9Mtz7t7vGYXD4UDb+WS2 T2Pw== 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=r89tSstUd87KxVgKJyc9fOJO7qDKtqqI7NTmITIB3KQ=; fh=hf24JvveL55vCfzfv0agRHDWsuhzZqIeZ7dfs5kcUjQ=; b=PYrJDCUE6kg76U6GDJefss8S/pNg0IXtZj+4ELSBU/CheonTx145R5iEumlFc1X/l4 5ZOjrJMvna17iiAa86TZ0eilQQllw1/IU5gvrPCFhdrlrpa3UlU5suOovUGALugocQAn N900Ap/kyGr296dxwW6ZoGLPh8iKWKmMUHKhFbQfq6j9U7sX+/l9LC9TyStqA2Ioc/cA wfZBymoQiMvl5BBxEo3ulFwiGSEfUw4+1RFoHb/r13iglvhdmCoPxhtLIC8uRI+tPd/W sMjcN+mtDLSAc/KrgmuCdb8P9A5jSfbuPTimOzUvb5iKHxNDs9/wKqbMOaVDr9Asbv3c K4bw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=tsqVZDBr; 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=kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id op10-20020a170906bcea00b00991f9e2a81asi2291093ejb.238.2023.07.11.07.22.21; Tue, 11 Jul 2023 07:22:45 -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=@kernel.org header.s=k20201202 header.b=tsqVZDBr; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233462AbjGKOPq (ORCPT + 99 others); Tue, 11 Jul 2023 10:15:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52712 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233445AbjGKOPo (ORCPT ); Tue, 11 Jul 2023 10:15:44 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 79870B0; Tue, 11 Jul 2023 07:15:43 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 16C1D6150D; Tue, 11 Jul 2023 14:15:43 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0848FC433C8; Tue, 11 Jul 2023 14:15:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1689084942; bh=B/xbZAcfESero9MbnK8hn07jc1YnxzqHt+73/OKFhoI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=tsqVZDBrt4sxiMKWtpCFTvByTQZFO7mAdGegliLhzJXs15V7YqWsqgnHerRcec5U+ Q/aaehktA8TSQGy3P2IRj2d9B6EYVTJ+OCKfI/Tfo17m6Rqe1hWpQQW6gLX9r7YOzV VeakEbJVbz9A5ixmsRtkWbHgzaYCL5u/Y7fFK/4vK2ugWUfhC94NjpyxXdz0df++TV 6Zqq6oeZmITh9QUwuYUDk8+gH+gny3tsYjFJqtLbbAFf99Us4d5y94mShmPB1DbFXl ggzQkydSW+OAFgriURtQRzGL9eaRhw2gcBBwwp+58HckLCUKp+XJm+/88Uiegq+3y2 vRhEWB1Io84fA== From: "Masami Hiramatsu (Google)" To: Steven Rostedt Cc: Dan Carpenter , linux-trace-kernel@vger.kernel.org, LKML , Masami Hiramatsu Subject: [PATCH v5 2/5] tracing/probes: Fix not to count error code to total length Date: Tue, 11 Jul 2023 23:15:38 +0900 Message-Id: <168908493827.123124.2175257289106364229.stgit@devnote2> X-Mailer: git-send-email 2.25.1 In-Reply-To: <168908491977.123124.16583481716284477889.stgit@devnote2> References: <168908491977.123124.16583481716284477889.stgit@devnote2> User-Agent: StGit/0.19 MIME-Version: 1.0 X-Spam-Status: No, score=-7.1 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,T_SCC_BODY_TEXT_LINE 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 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1771134376678683387 X-GMAIL-MSGID: 1771134376678683387 From: Masami Hiramatsu (Google) Fix not to count the error code (which is minus value) to the total used length of array, because it can mess up the return code of process_fetch_insn_bottom(). Also clear the 'ret' value because it will be used for calculating next data_loc entry. Reported-by: Dan Carpenter Closes: https://lore.kernel.org/all/8819b154-2ba1-43c3-98a2-cbde20892023@moroto.mountain/ Fixes: 9b960a38835f ("tracing: probeevent: Unify fetch_insn processing common part") Cc: stable@vger.kernel.org Signed-off-by: Masami Hiramatsu (Google) Reviewed-by: Steven Rostedt (Google) --- kernel/trace/trace_probe_tmpl.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/kernel/trace/trace_probe_tmpl.h b/kernel/trace/trace_probe_tmpl.h index 4735c5cb76fa..ed9d57c6b041 100644 --- a/kernel/trace/trace_probe_tmpl.h +++ b/kernel/trace/trace_probe_tmpl.h @@ -204,6 +204,8 @@ process_fetch_insn_bottom(struct fetch_insn *code, unsigned long val, array: /* the last stage: Loop on array */ if (code->op == FETCH_OP_LP_ARRAY) { + if (ret < 0) + ret = 0; total += ret; if (++i < code->param) { code = s3; From patchwork Tue Jul 11 14:15:48 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Masami Hiramatsu (Google)" X-Patchwork-Id: 118572 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:a6b2:0:b0:3e4:2afc:c1 with SMTP id c18csp525915vqm; Tue, 11 Jul 2023 07:36:12 -0700 (PDT) X-Google-Smtp-Source: APBJJlHDRJQGHvLhoN8S7akvFeJ6pq/CV59+y4rvoCnzOuvu1iERuz5/tFdABSM+Pf3EE0SITEci X-Received: by 2002:aa7:d50d:0:b0:51d:fa7c:c330 with SMTP id y13-20020aa7d50d000000b0051dfa7cc330mr16307816edq.26.1689086171902; Tue, 11 Jul 2023 07:36:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689086171; cv=none; d=google.com; s=arc-20160816; b=O7Q5yJZ0YqinhU3TBikuOp2o5QvdE+3gfkG7Vfvi6k2EWe7IVWKrpU21YFlcHaVpW5 dJ/cFSZR4vRMhenzdokeMW2JCvC3K+2FUYY50xfSIccCl7r1NcJS16MHt+TK60eow5bf MByM/X1x+m4aS1MqVE7sXwmWEyjRRmYaKZQ3cgXFVHr6DjRDc2gVQ+xkgjb3liVVItXT fA6+ylONgaD7yWcbxu2Kq4gH8chVWTxuwx5Kay/G3ZmcPChaTf0qVmJm++4kRcCNy25S 8mfcAjWzzJw9tD6oMzJvZeFF6L7NRJPGHAOWDvjdmfvITFbdmOkP8+o8k0EUvVXCev/Y hXtw== 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=d+NOB/WONAqzzZgmWSMzf9e8LMOvk34KXJAn/twOYSk=; fh=hf24JvveL55vCfzfv0agRHDWsuhzZqIeZ7dfs5kcUjQ=; b=p3AM0BdMcCNzNhkT3ydn4ke8IoGPVbaBQm26yrQHAkXz+Qdwj0y/RUzjISFRILcYNR 323ZksiX7/3nyN9cS66Dhi8IQ4f7Z5JPxPi5nKOMbI7MmFsMEsp2I/F7t9yrh3LpHDZc zULzj363nC1XQhwMjhvM2/ML7gFuxcNhd/oFdgCgQyW8lDj4mFIYfGtGcyWn+OlhbusU q+6K4WgbbnOpkyMxWvEW9nuH+yMuyNhBQaIWvKENDnCRZTeVQryDmWncBBCABesmjlVU dVmouMZbcuqM2gV1xnH8dCwfR69iVXkkxlbfrE2GKyWhAc/d8NdBtj5LW0PzSR0KBTEb eG7g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=aReD0A+1; 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=kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id d12-20020aa7c1cc000000b0051e26731172si2055205edp.672.2023.07.11.07.35.47; Tue, 11 Jul 2023 07:36:11 -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=@kernel.org header.s=k20201202 header.b=aReD0A+1; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232906AbjGKOP7 (ORCPT + 99 others); Tue, 11 Jul 2023 10:15:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52992 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232888AbjGKOPy (ORCPT ); Tue, 11 Jul 2023 10:15:54 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4C6C8170A; Tue, 11 Jul 2023 07:15:53 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id D15646150C; Tue, 11 Jul 2023 14:15:52 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id CEEF1C433C8; Tue, 11 Jul 2023 14:15:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1689084952; bh=5Y9sWGJd4HJzLogg+iWU8edbrK9/5rH7d1aurm3YzgM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=aReD0A+1tRpSeAhG5xZHxoEfgPqj/cIAjHv5Z4zOwhd3S7Z4wLSHzDiwKz3dWmVPB olT6rBr8eKo6yrOVIN/QlfyLwLhToLP9rNvm0gIdSpX9aPA+9Yv/6SL/7J4uqSsMjC zHrhLLgcGapkXdRl+Ga4UB03d368RaOzFaoU+ILQhCICSDUW3gzAxhTD7Lfo+Kuvxt jOoJdydJtXRmH/EoxUaPd5caAnHcUz2ElaFcA6ig8tiPnq09t6IiIXQSMuljQ9RAXQ rXpVzluE6t3+fiwKXb4yON3bOY56bvM08Pj3bzk8blEgezzi7N3HgIcOYDgMs6nFk8 LWHO/woKPxf4A== From: "Masami Hiramatsu (Google)" To: Steven Rostedt Cc: Dan Carpenter , linux-trace-kernel@vger.kernel.org, LKML , Masami Hiramatsu Subject: [PATCH v5 3/5] tracing/probes: Fix to update dynamic data counter if fetcharg uses it Date: Tue, 11 Jul 2023 23:15:48 +0900 Message-Id: <168908494781.123124.8160245359962103684.stgit@devnote2> X-Mailer: git-send-email 2.25.1 In-Reply-To: <168908491977.123124.16583481716284477889.stgit@devnote2> References: <168908491977.123124.16583481716284477889.stgit@devnote2> User-Agent: StGit/0.19 MIME-Version: 1.0 X-Spam-Status: No, score=-7.1 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,T_SCC_BODY_TEXT_LINE 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 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1771135221847571799 X-GMAIL-MSGID: 1771135221847571799 From: Masami Hiramatsu (Google) Fix to update dynamic data counter ('dyndata') and max length ('maxlen') only if the fetcharg uses the dynamic data. Also get out arg->dynamic from unlikely(). This makes dynamic data address wrong if process_fetch_insn() returns error on !arg->dynamic case. Suggested-by: Steven Rostedt Link: https://lore.kernel.org/all/20230710233400.5aaf024e@gandalf.local.home/ Fixes: 9178412ddf5a ("tracing: probeevent: Return consumed bytes of dynamic area") Cc: stable@vger.kernel.org Signed-off-by: Masami Hiramatsu (Google) Reviewed-by: Steven Rostedt (Google) --- kernel/trace/trace_probe_tmpl.h | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/kernel/trace/trace_probe_tmpl.h b/kernel/trace/trace_probe_tmpl.h index ed9d57c6b041..185da001f4c3 100644 --- a/kernel/trace/trace_probe_tmpl.h +++ b/kernel/trace/trace_probe_tmpl.h @@ -267,11 +267,13 @@ store_trace_args(void *data, struct trace_probe *tp, void *rec, if (unlikely(arg->dynamic)) *dl = make_data_loc(maxlen, dyndata - base); ret = process_fetch_insn(arg->code, rec, dl, base); - if (unlikely(ret < 0 && arg->dynamic)) { - *dl = make_data_loc(0, dyndata - base); - } else { - dyndata += ret; - maxlen -= ret; + if (arg->dynamic) { + if (unlikely(ret < 0)) { + *dl = make_data_loc(0, dyndata - base); + } else { + dyndata += ret; + maxlen -= ret; + } } } } From patchwork Tue Jul 11 14:15:57 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Masami Hiramatsu (Google)" X-Patchwork-Id: 118569 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:a6b2:0:b0:3e4:2afc:c1 with SMTP id c18csp525189vqm; Tue, 11 Jul 2023 07:35:02 -0700 (PDT) X-Google-Smtp-Source: APBJJlFYW5uwe4mR7o7t9TIfmF9q+WLUoXBwBdCMy9ae9ky4fYxpIsnITv/jv297kjR5M5+Ovh/h X-Received: by 2002:a17:906:74d8:b0:988:57b4:2853 with SMTP id z24-20020a17090674d800b0098857b42853mr18227968ejl.25.1689086101755; Tue, 11 Jul 2023 07:35:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689086101; cv=none; d=google.com; s=arc-20160816; b=Z1xX+f/JQSNb0tumCg+Gga712KgG/ItzHQhkcfVIP7fjnxyacRHDzPjPcN7tau/bby PrkUiYqGoCE590f/ZgShDKxFZUper/4ccS/k+YX4ZFGfhk2UyhvrnVzPK/c/xkzSfyip Nbwvi7o5kpp+kwYkcmrq5xry14iOG0uw1Y/TSRwFhzc5Q0uLGGQNLvwKnzUfP1R4lwPt Xeu1QRS+xIlLm84hhrUa3cpwwvdtBAlHw6pN2BeuwUdyIYg9/YKdnhbNwJx9pcRaPIdB bzP7BBgH3MGPcgQ8MpWXsHq9DIXncdXMwynxVX0Hvo0s0+Mw+2ofsxZCZxc4odqAZCAC 7dZg== 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=VFoKItDzYCaOWn4fgODDX8b+SEBOBqzdSJDV3zBHSYA=; fh=hf24JvveL55vCfzfv0agRHDWsuhzZqIeZ7dfs5kcUjQ=; b=U/XYCnXu03mR7YwTTqi0m3Ce+ZTDHkYeG4Lb2muvkpL+EJkReJxXS+D6esgSR4r8l1 Xq39nCGpW4IxVNoUpm2y4LdwZLmjTrE1YkLx4Ak4TmCgaep1FL+O+mQV1p+uWiSPzAR5 oRiYzySoM7sxbf0hU8+k6JSf0ZhXCXwcdCcWX8Ul1m4puhi29YL8L/BTTcl3d35677HB fq4XMiFAt2JzsXzCam004/0Q0g8U7OD1R6v8jkdtBIlVWRfvXaJryvw6fIc9R+i5jC73 Lr4zjbfWf8/ScMFgZt9Wr6vxuHiv/zRGc1Nm6AlUa+h9QKde0OgGRT5NRN4tv69Cvlq7 WtZQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=XYHmYYZt; 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=kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id o15-20020a1709062e8f00b009787b15aa51si2105630eji.713.2023.07.11.07.34.38; Tue, 11 Jul 2023 07:35:01 -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=@kernel.org header.s=k20201202 header.b=XYHmYYZt; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232101AbjGKOQN (ORCPT + 99 others); Tue, 11 Jul 2023 10:16:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53284 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233484AbjGKOQG (ORCPT ); Tue, 11 Jul 2023 10:16:06 -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 B50FF1708; Tue, 11 Jul 2023 07:16:02 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 1487F614E2; Tue, 11 Jul 2023 14:16:02 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3FB75C433C9; Tue, 11 Jul 2023 14:16:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1689084961; bh=LOMI4wDzsq/hXAQmAMNQ62g25jda2U1iBQmNIJ7a+L8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=XYHmYYZtT9DWZF9d0bff3fSO3KXst8iYe5u/AyxO+3aKqfGuNsE4/ihcXTYjwXxPx 3aa9a3hL1//H/yyyNqTEMBy3YTZPMJ2KwuSjX9I6Fk/7HrNXpE+icCGRokFsH+BPY1 +PAN87G7p16i7VECnrs71be8M2bMGTffjNocZwQyD1J/ssIt4YIoGCMHB67U2Q05QA w1sLS0LOxXwA0n3wOCApwFca6rXUruLfxD/EUISDEVzDA43qxKjqOS19nmvZ5Gml9l ft2ZZ7MKL8ilVno+SARlP+TwK+WYrB+DncCyjTHy46S0i7wOhaz9fC/AAFumEtZb1t aDz+ax7OfMICg== From: "Masami Hiramatsu (Google)" To: Steven Rostedt Cc: Dan Carpenter , linux-trace-kernel@vger.kernel.org, LKML , Masami Hiramatsu Subject: [PATCH v5 4/5] Revert "tracing: Add "(fault)" name injection to kernel probes" Date: Tue, 11 Jul 2023 23:15:57 +0900 Message-Id: <168908495772.123124.1250788051922100079.stgit@devnote2> X-Mailer: git-send-email 2.25.1 In-Reply-To: <168908491977.123124.16583481716284477889.stgit@devnote2> References: <168908491977.123124.16583481716284477889.stgit@devnote2> User-Agent: StGit/0.19 MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE 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 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1771135148078608564 X-GMAIL-MSGID: 1771135148078608564 From: Masami Hiramatsu (Google) This reverts commit 2e9906f84fc7c99388bb7123ade167250d50f1c0. It was turned out that commit 2e9906f84fc7 ("tracing: Add "(fault)" name injection to kernel probes") did not work correctly and probe events still show just '(fault)' (instead of '"(fault)"'). Also, current '(fault)' is more explicit that it faulted. This also moves FAULT_STRING macro to trace.h so that synthetic event can keep using it, and uses it in trace_probe.c too. Link: https://lore.kernel.org/all/20230706230642.3793a593@rorschach.local.home/ Cc: stable@vger.kernel.org Cc: Andrew Morton Cc: Tom Zanussi Signed-off-by: Masami Hiramatsu (Google) Reviewed-by: Steven Rostedt (Google) --- kernel/trace/trace.h | 2 ++ kernel/trace/trace_probe.c | 2 +- kernel/trace/trace_probe_kernel.h | 31 ++++++------------------------- 3 files changed, 9 insertions(+), 26 deletions(-) diff --git a/kernel/trace/trace.h b/kernel/trace/trace.h index 79bdefe9261b..eee1f3ca4749 100644 --- a/kernel/trace/trace.h +++ b/kernel/trace/trace.h @@ -113,6 +113,8 @@ enum trace_type { #define MEM_FAIL(condition, fmt, ...) \ DO_ONCE_LITE_IF(condition, pr_err, "ERROR: " fmt, ##__VA_ARGS__) +#define FAULT_STRING "(fault)" + #define HIST_STACKTRACE_DEPTH 16 #define HIST_STACKTRACE_SIZE (HIST_STACKTRACE_DEPTH * sizeof(unsigned long)) #define HIST_STACKTRACE_SKIP 5 diff --git a/kernel/trace/trace_probe.c b/kernel/trace/trace_probe.c index 2d2616678295..591399ddcee5 100644 --- a/kernel/trace/trace_probe.c +++ b/kernel/trace/trace_probe.c @@ -65,7 +65,7 @@ int PRINT_TYPE_FUNC_NAME(string)(struct trace_seq *s, void *data, void *ent) int len = *(u32 *)data >> 16; if (!len) - trace_seq_puts(s, "(fault)"); + trace_seq_puts(s, FAULT_STRING); else trace_seq_printf(s, "\"%s\"", (const char *)get_loc_data(data, ent)); diff --git a/kernel/trace/trace_probe_kernel.h b/kernel/trace/trace_probe_kernel.h index c4e1d4c03a85..6deae2ce34f8 100644 --- a/kernel/trace/trace_probe_kernel.h +++ b/kernel/trace/trace_probe_kernel.h @@ -2,8 +2,6 @@ #ifndef __TRACE_PROBE_KERNEL_H_ #define __TRACE_PROBE_KERNEL_H_ -#define FAULT_STRING "(fault)" - /* * This depends on trace_probe.h, but can not include it due to * the way trace_probe_tmpl.h is used by trace_kprobe.c and trace_eprobe.c. @@ -15,16 +13,8 @@ static nokprobe_inline int fetch_store_strlen_user(unsigned long addr) { const void __user *uaddr = (__force const void __user *)addr; - int ret; - ret = strnlen_user_nofault(uaddr, MAX_STRING_SIZE); - /* - * strnlen_user_nofault returns zero on fault, insert the - * FAULT_STRING when that occurs. - */ - if (ret <= 0) - return strlen(FAULT_STRING) + 1; - return ret; + return strnlen_user_nofault(uaddr, MAX_STRING_SIZE); } /* Return the length of string -- including null terminal byte */ @@ -44,18 +34,7 @@ fetch_store_strlen(unsigned long addr) len++; } while (c && ret == 0 && len < MAX_STRING_SIZE); - /* For faults, return enough to hold the FAULT_STRING */ - return (ret < 0) ? strlen(FAULT_STRING) + 1 : len; -} - -static nokprobe_inline void set_data_loc(int ret, void *dest, void *__dest, void *base, int len) -{ - if (ret >= 0) { - *(u32 *)dest = make_data_loc(ret, __dest - base); - } else { - strscpy(__dest, FAULT_STRING, len); - ret = strlen(__dest) + 1; - } + return (ret < 0) ? ret : len; } /* @@ -76,7 +55,8 @@ fetch_store_string_user(unsigned long addr, void *dest, void *base) __dest = get_loc_data(dest, base); ret = strncpy_from_user_nofault(__dest, uaddr, maxlen); - set_data_loc(ret, dest, __dest, base, maxlen); + if (ret >= 0) + *(u32 *)dest = make_data_loc(ret, __dest - base); return ret; } @@ -107,7 +87,8 @@ fetch_store_string(unsigned long addr, void *dest, void *base) * probing. */ ret = strncpy_from_kernel_nofault(__dest, (void *)addr, maxlen); - set_data_loc(ret, dest, __dest, base, maxlen); + if (ret >= 0) + *(u32 *)dest = make_data_loc(ret, __dest - base); return ret; } From patchwork Tue Jul 11 14:16:07 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Masami Hiramatsu (Google)" X-Patchwork-Id: 118584 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:a6b2:0:b0:3e4:2afc:c1 with SMTP id c18csp528488vqm; Tue, 11 Jul 2023 07:40:25 -0700 (PDT) X-Google-Smtp-Source: APBJJlGSNPsHhl9ffhJMlVOoTLXgVOP762g2Y55ax7wWeZoCaawU/mSHcoAOd6syzL7SdMNElCp1 X-Received: by 2002:a17:906:71b:b0:992:4d30:dc4a with SMTP id y27-20020a170906071b00b009924d30dc4amr13166527ejb.74.1689086425009; Tue, 11 Jul 2023 07:40:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689086424; cv=none; d=google.com; s=arc-20160816; b=x8zS8s1Ryva8wRDitRKl254MRiQyxRbyHTCrWso0Kq/M+wlR9g0h3xNIvMrvMPeKKi LichDnv7rQ2dm12YsF6SzuK1cQdJ3y8ejHQR16NGWkUapY+NKB5omftAPMhZD3TvtYcS r40P70yf6eOkHSulXNaJ+cI9mQ1WeKX7IRhFoxScV8QWca+i1YjvvzRi8UwUuJAX2bRs BMMrh9KdVjiQXuSX8myh2WlpmiOayEs6uxR5gpT0IpkyxBPWbwaNsatbn/wYze+3aPgP n27nd5QUmI2zz+FPVjMl8fazvhDTyxbal/sob+VrJqblSP/mIZiLWGNmb5WJV9eS9Rt0 oATQ== 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=08mwoeNex3JyB0lbYCQ+c/MT3GHc9ofwlZf7CF6B6OI=; fh=hf24JvveL55vCfzfv0agRHDWsuhzZqIeZ7dfs5kcUjQ=; b=ASd7jFnRDMCGc19Ac6//CQ+tDM88a7VRdxVqUbUkAcYQWexUbTVXCR+iWFv43IG2B4 CkD7KK10A5YQIpi7o2BfOR1eCkVga8MFzQjxA8NiSC2bhqP586YLvnHXuWSA/uzSCNhR ZFlse99UFtaCv38EVvQJOtrfRrBQzSj8RMHT+FGLo823U/rW/eMgffmSxWozXw8fqdlE fUROn1vESvWAcyZPK+quSZkYemqiZFBGHKbBq12zQLZQ5lHGWlDl+k1i2wgENewxHpxZ kI2PmtfDcnvJAJziidpe2efL3Gs+clWfa0qf/1kYR6mDXaUoz5JUpxYwGkUWxHGd14Ik ddFQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=HzBtSrQ0; 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=kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id g9-20020a170906520900b009937256ad95si2338488ejm.370.2023.07.11.07.40.01; Tue, 11 Jul 2023 07:40:24 -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=@kernel.org header.s=k20201202 header.b=HzBtSrQ0; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232415AbjGKOQY (ORCPT + 99 others); Tue, 11 Jul 2023 10:16:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53268 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231344AbjGKOQP (ORCPT ); Tue, 11 Jul 2023 10:16:15 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 36795170C; Tue, 11 Jul 2023 07:16:12 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 9E32B61360; Tue, 11 Jul 2023 14:16:11 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D971EC433C7; Tue, 11 Jul 2023 14:16:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1689084971; bh=/AcWrvIXlV70CD4DdIzY6zl/jRyB0t5UfH4qkA2Xy84=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=HzBtSrQ0OIc31FCAGpYEiDxSYZ9C7gi2brxAmdhKAjQzFnWncfRIkqSFPwCj/gDiH YyQf+yI7ZnoFasEbnIQS8hkl2puowcYyNIdEniwzrsfvMfRrq6y2Xvu/gSXo0sMCVY Up85DELswwwq+gR6Q8C5RRdXjsEp7ME6tkvLfR/8YCA9pr4KwGeFnF+cfZYdYuzeZL d8W6oLO8uFC8PWIaCYK7wmqVOCuDf0m7kgkFOdgS90shxLRAUnxVDKXbOXySLMXyi2 GDRiUMmEcHEES66mWtk0Lu2PcrnRT8w8c9kJrKGnrFaI146XD5GGJWxfw0BvEV9wKg I9NvDkmTPNK5g== From: "Masami Hiramatsu (Google)" To: Steven Rostedt Cc: Dan Carpenter , linux-trace-kernel@vger.kernel.org, LKML , Masami Hiramatsu Subject: [PATCH v5 5/5] tracing/probes: Fix to record 0-length data_loc in fetch_store_string*() if fails Date: Tue, 11 Jul 2023 23:16:07 +0900 Message-Id: <168908496683.123124.4761206188794205601.stgit@devnote2> X-Mailer: git-send-email 2.25.1 In-Reply-To: <168908491977.123124.16583481716284477889.stgit@devnote2> References: <168908491977.123124.16583481716284477889.stgit@devnote2> User-Agent: StGit/0.19 MIME-Version: 1.0 X-Spam-Status: No, score=-7.1 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,T_SCC_BODY_TEXT_LINE 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 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1771135486957611936 X-GMAIL-MSGID: 1771135486957611936 From: Masami Hiramatsu (Google) Fix to record 0-length data to data_loc in fetch_store_string*() if it fails to get the string data. Currently those expect that the data_loc is updated by store_trace_args() if it returns the error code. However, that does not work correctly if the argument is an array of strings. In that case, store_trace_args() only clears the first entry of the array (which may have no error) and leaves other entries. So it should be cleared by fetch_store_string*() itself. Also, 'dyndata' and 'maxlen' in store_trace_args() should be updated only if it is used (ret > 0 and argument is a dynamic data.) Fixes: 40b53b771806 ("tracing: probeevent: Add array type support") Cc: stable@vger.kernel.org Signed-off-by: Masami Hiramatsu (Google) Reviewed-by: Steven Rostedt (Google) --- Changes in v4: - Simplify the updating data_loc code with set_data_loc(). Changes in v5: - Move out arg->dynamic check from unlikely() and use likely(). --- kernel/trace/trace_probe_kernel.h | 13 +++++++++---- kernel/trace/trace_probe_tmpl.h | 10 +++------- kernel/trace/trace_uprobe.c | 3 ++- 3 files changed, 14 insertions(+), 12 deletions(-) diff --git a/kernel/trace/trace_probe_kernel.h b/kernel/trace/trace_probe_kernel.h index 6deae2ce34f8..bb723eefd7b7 100644 --- a/kernel/trace/trace_probe_kernel.h +++ b/kernel/trace/trace_probe_kernel.h @@ -37,6 +37,13 @@ fetch_store_strlen(unsigned long addr) return (ret < 0) ? ret : len; } +static nokprobe_inline void set_data_loc(int ret, void *dest, void *__dest, void *base) +{ + if (ret < 0) + ret = 0; + *(u32 *)dest = make_data_loc(ret, __dest - base); +} + /* * Fetch a null-terminated string from user. Caller MUST set *(u32 *)buf * with max length and relative data location. @@ -55,8 +62,7 @@ fetch_store_string_user(unsigned long addr, void *dest, void *base) __dest = get_loc_data(dest, base); ret = strncpy_from_user_nofault(__dest, uaddr, maxlen); - if (ret >= 0) - *(u32 *)dest = make_data_loc(ret, __dest - base); + set_data_loc(ret, dest, __dest, base); return ret; } @@ -87,8 +93,7 @@ fetch_store_string(unsigned long addr, void *dest, void *base) * probing. */ ret = strncpy_from_kernel_nofault(__dest, (void *)addr, maxlen); - if (ret >= 0) - *(u32 *)dest = make_data_loc(ret, __dest - base); + set_data_loc(ret, dest, __dest, base); return ret; } diff --git a/kernel/trace/trace_probe_tmpl.h b/kernel/trace/trace_probe_tmpl.h index 185da001f4c3..3935b347f874 100644 --- a/kernel/trace/trace_probe_tmpl.h +++ b/kernel/trace/trace_probe_tmpl.h @@ -267,13 +267,9 @@ store_trace_args(void *data, struct trace_probe *tp, void *rec, if (unlikely(arg->dynamic)) *dl = make_data_loc(maxlen, dyndata - base); ret = process_fetch_insn(arg->code, rec, dl, base); - if (arg->dynamic) { - if (unlikely(ret < 0)) { - *dl = make_data_loc(0, dyndata - base); - } else { - dyndata += ret; - maxlen -= ret; - } + if (arg->dynamic && likely(ret > 0)) { + dyndata += ret; + maxlen -= ret; } } } diff --git a/kernel/trace/trace_uprobe.c b/kernel/trace/trace_uprobe.c index 8b92e34ff0c8..7b47e9a2c010 100644 --- a/kernel/trace/trace_uprobe.c +++ b/kernel/trace/trace_uprobe.c @@ -170,7 +170,8 @@ fetch_store_string(unsigned long addr, void *dest, void *base) */ ret++; *(u32 *)dest = make_data_loc(ret, (void *)dst - base); - } + } else + *(u32 *)dest = make_data_loc(0, (void *)dst - base); return ret; }