Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp70449imm; Wed, 5 Sep 2018 15:10:13 -0700 (PDT) X-Google-Smtp-Source: ANB0VdZPZYadxRCPKGAbKbPJZS2KaLMG4ehJEVH0LMN1k92tEnhck99TdvMKr5Xzc75LOSMF+cR8 X-Received: by 2002:a62:45d2:: with SMTP id n79-v6mr42864433pfi.137.1536185413903; Wed, 05 Sep 2018 15:10:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1536185413; cv=none; d=google.com; s=arc-20160816; b=UfQuzGF4Tokg5apbzHd6cG7H5Obj6cFtB7Yq2JVCb4+Fu6H48LyRqKRgcIOEMgOHlb 79+3AKkXHBZUbLgQOb0VFepDgTCN6QpaiyI2N0dAvPX2Q6PXyFFvoGKMJf6TWsZ0vvmC BLzusRJTdOejOJEPZOtF5jkRJooKam1uNOeKQg5hlQ261yFTAujVNCpumed8bN0uBz9D YHokf34/AlWcrdfTrBQnD6SKN0nu9giRHz0N3rjmmV9rQ9aJ6aV4ObhJILY1uJ9blxhM eoCktqoVbwJaoDHcDltUUHU2xD+I5qd92hnsLn3QsD/LI0dy81ogQdiPr4uvj0il7b9X 4sgg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=mY9vwEo+Ar9kHJw4O9gEbcDJWGkm9QtgPsLOv31dsgY=; b=KQn1eKQjVnbHFkiFnPJSdvaC801BBVhf/Evu8l0RYzj3K5qZ9dgP6L1QJlvzVF+tOt MmUtzyPs24XJkNLCebuXGo9G0dlw9d1f8Kod+vBb6xGtbnTysZCEWCvkmsMbDSiT/Oow aUESLaEgk1BoXucuIVcOJf0GvSWjAcVyEqvUWhCZEF0iZQ7Ihqs6KNEGHyO0c3YSbnPa IGLZQ45M7gzJF0/EontdII1LMvARzr36QOV+XhCscgnswEDlvu4TCDDKScsw/fKcUwA3 +Vvfoqb5bb0dDG/CoAF3EGaHndh3irrQn7Fgwbf46vLGtCmOZSN8+6hlCMdu2VteItcs zwJg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=kUH328xf; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a64-v6si3456252pfb.224.2018.09.05.15.09.58; Wed, 05 Sep 2018 15:10:13 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=kUH328xf; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 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 S1729069AbeIFCkY (ORCPT + 99 others); Wed, 5 Sep 2018 22:40:24 -0400 Received: from mail.kernel.org ([198.145.29.99]:55454 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728517AbeIFCkX (ORCPT ); Wed, 5 Sep 2018 22:40:23 -0400 Received: from jouet.infradead.org (unknown [179.97.41.186]) (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 9E93220839; Wed, 5 Sep 2018 22:08:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1536185291; bh=2ccCmedq/akhotJr6EgqLmC5fee7v91d0BjkFlafK1E=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=kUH328xfwqP7QLn+GOh2KGeQYG18j6x8DzlUt2EZVR4ZDMrIoNL0MwbRVKTNUbk7v qJKUKATePqCBqjs0GuKobTrMBj2Tp+TjlUlAYWYaFHp/66pSIE1re38DIeEojeoFhN lXjtLqa3mWuYmzW0bbEOsSmvxWk62Samfg/2NEDo= From: Arnaldo Carvalho de Melo To: Ingo Molnar Cc: Clark Williams , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, Arnaldo Carvalho de Melo , Adrian Hunter , Daniel Borkmann , David Ahern , Jiri Olsa , Namhyung Kim , Wang Nan , Yonghong Song Subject: [PATCH 71/77] perf augmented_syscalls: Check probe_read_str() return separately Date: Wed, 5 Sep 2018 19:04:34 -0300 Message-Id: <20180905220440.20256-72-acme@kernel.org> X-Mailer: git-send-email 2.14.4 In-Reply-To: <20180905220440.20256-1-acme@kernel.org> References: <20180905220440.20256-1-acme@kernel.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Arnaldo Carvalho de Melo Using a value returned from probe_read_str() to tell how many bytes to copy using perf_event_output() has issues in some older kernels, like 4.17.17-100.fc27.x86_64, so separate the bounds checking done on how many bytes to copy to a separate variable, so that the next patch has only what is being done to make the test pass on older BPF validators. For reference, see the discussion in this thread: https://www.spinics.net/lists/netdev/msg480099.html Cc: Adrian Hunter Cc: Daniel Borkmann Cc: David Ahern Cc: Jiri Olsa Cc: Namhyung Kim Cc: Wang Nan Cc: Yonghong Song Link: https://lkml.kernel.org/n/tip-jtsapwibyxrnv1xjfsgzp0fj@git.kernel.org Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/examples/bpf/augmented_syscalls.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/tools/perf/examples/bpf/augmented_syscalls.c b/tools/perf/examples/bpf/augmented_syscalls.c index 1419a9186937..0decbcfa8b90 100644 --- a/tools/perf/examples/bpf/augmented_syscalls.c +++ b/tools/perf/examples/bpf/augmented_syscalls.c @@ -33,9 +33,9 @@ struct syscall_exit_args { }; struct augmented_filename { - int size; - int reserved; - char value[256]; + unsigned int size; + int reserved; + char value[256]; }; #define augmented_filename_syscall(syscall) \ @@ -46,14 +46,15 @@ struct augmented_enter_##syscall##_args { \ int syscall_enter(syscall)(struct syscall_enter_##syscall##_args *args) \ { \ struct augmented_enter_##syscall##_args augmented_args = { .filename.reserved = 0, }; \ + unsigned int len = sizeof(augmented_args); \ probe_read(&augmented_args.args, sizeof(augmented_args.args), args); \ augmented_args.filename.size = probe_read_str(&augmented_args.filename.value, \ sizeof(augmented_args.filename.value), \ args->filename_ptr); \ + if (augmented_args.filename.size < sizeof(augmented_args.filename.value)) \ + len -= sizeof(augmented_args.filename.value) - augmented_args.filename.size; \ perf_event_output(args, &__augmented_syscalls__, BPF_F_CURRENT_CPU, \ - &augmented_args, \ - (sizeof(augmented_args) - sizeof(augmented_args.filename.value) + \ - augmented_args.filename.size)); \ + &augmented_args, len); \ return 0; \ } \ int syscall_exit(syscall)(struct syscall_exit_args *args) \ -- 2.14.4