Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp4093282imm; Mon, 17 Sep 2018 08:06:18 -0700 (PDT) X-Google-Smtp-Source: ANB0VdaCO+ifSt37EJZWm4dEHFmJXu+G0P9VK1hrHr6ntByspZiA3LWRHD4ukstjjOC9U0q5LSc4 X-Received: by 2002:a62:de04:: with SMTP id h4-v6mr26239271pfg.258.1537196778284; Mon, 17 Sep 2018 08:06:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1537196778; cv=none; d=google.com; s=arc-20160816; b=s46uV3QqZUgZ534FwhvPuwAjC2J+Lug90e0wfqu+fUN6k2JGW6p9Xb3d7fIQi67VEf Pp+8T/YCe7fPRpk3dgJ4LaDYFH7lKCtEQconFBAByCsAnniyLCI22OxVrPKeR9DxCvaH 09HKq2xHLqqXShAZuwAfbrLIabyV9gYaqFZVJZqJFk5KevNjotwq0ht1eQ9upVp0YRE1 xcL0u23QkXa8guSR09Z+PzVCqSDn4Fihz4rP3pF1JcRGHAFIk4qk5qpucYNU68ZV4A/D eUbkfnaE0XbwyjzzKS4u3WUmxhda53AWvC5sjZmGg0LEWPqDhCpIzu6BvS+gRT5pmCVP iCDQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:message-id:date:subject:cc :to:from; bh=uWQlCD/xnEHAUzT7y+fOBZzsbeM4fs0+JN5W7zVWk40=; b=Gc0RsY0ABHLGJ+fqFsiBOGf4t/zwaQ4INJgshrYvFzTpSBVh5ZadzUK/aRZMBt3YIo b5GvE9Q7gcfin+qXXzEbo2nayFqVCYi/YibDCiDta9mye8scmrcz6y/GZptMBV2ZD8ob Uu0ES79f0ZwpzNMyrt1TTUVKq3CSCBIFJLui+irO/gTFkyAsA5yi539ZdDFsJoxXNayn Igu69POWk5VJyzYHbJcupeE5hqOvP3Yf7Ez/IJUq/hOJmxuZa0us0SemDGs34ivjf1dG WBPWzh23bB2T4HUYzh3DgVQusWIO0dJTs2DTnYAJ7eDPfnS2PqGEeL1yGhh20NK5K6T0 /1aQ== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b39-v6si17540944plb.484.2018.09.17.08.06.02; Mon, 17 Sep 2018 08:06:18 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729088AbeIQUdl (ORCPT + 99 others); Mon, 17 Sep 2018 16:33:41 -0400 Received: from szxga05-in.huawei.com ([45.249.212.191]:12168 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1728437AbeIQUdl (ORCPT ); Mon, 17 Sep 2018 16:33:41 -0400 Received: from DGGEMS412-HUB.china.huawei.com (unknown [172.30.72.60]) by Forcepoint Email with ESMTP id 79F8CF96C0871; Mon, 17 Sep 2018 23:05:52 +0800 (CST) Received: from linux-work.huawei.com (10.67.189.174) by DGGEMS412-HUB.china.huawei.com (10.3.19.212) with Microsoft SMTP Server id 14.3.399.0; Mon, 17 Sep 2018 23:05:48 +0800 From: nixiaoming To: , CC: , , Subject: [PATCH v2] fanotify reports the thread id of the event trigger Date: Mon, 17 Sep 2018 22:19:50 +0800 Message-ID: <20180917141950.111841-1-nixiaoming@huawei.com> X-Mailer: git-send-email 2.10.1 MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.67.189.174] X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org In order to identify which thread triggered the event in the multi-threaded program, add the FAN_EVENT_INFO_TID tag in fanotify_init to select whether to report the event creator's thread id information. Signed-off-by: nixiaoming --- fs/notify/fanotify/fanotify.c | 5 ++++- fs/notify/fanotify/fanotify_user.c | 5 +++-- include/linux/fsnotify_backend.h | 1 + include/uapi/linux/fanotify.h | 1 + 4 files changed, 9 insertions(+), 3 deletions(-) diff --git a/fs/notify/fanotify/fanotify.c b/fs/notify/fanotify/fanotify.c index 94b5215..5a3af87 100644 --- a/fs/notify/fanotify/fanotify.c +++ b/fs/notify/fanotify/fanotify.c @@ -171,7 +171,10 @@ struct fanotify_event_info *fanotify_alloc_event(struct fsnotify_group *group, goto out; init: __maybe_unused fsnotify_init_event(&event->fse, inode, mask); - event->tgid = get_pid(task_tgid(current)); + if (group->fanotify_data.should_report_tid) + event->tgid = get_pid(task_pid(current)); + else + event->tgid = get_pid(task_tgid(current)); if (path) { event->path = *path; path_get(&event->path); diff --git a/fs/notify/fanotify/fanotify_user.c b/fs/notify/fanotify/fanotify_user.c index 6905488..3aa425b 100644 --- a/fs/notify/fanotify/fanotify_user.c +++ b/fs/notify/fanotify/fanotify_user.c @@ -693,9 +693,9 @@ SYSCALL_DEFINE2(fanotify_init, unsigned int, flags, unsigned int, event_f_flags) return -EPERM; #ifdef CONFIG_AUDITSYSCALL - if (flags & ~(FAN_ALL_INIT_FLAGS | FAN_ENABLE_AUDIT)) + if (flags & ~(FAN_ALL_INIT_FLAGS | FAN_ENABLE_AUDIT | FAN_EVENT_INFO_TID)) #else - if (flags & ~FAN_ALL_INIT_FLAGS) + if (flags & ~(FAN_ALL_INIT_FLAGS | FAN_EVENT_INFO_TID)) #endif return -EINVAL; @@ -731,6 +731,7 @@ SYSCALL_DEFINE2(fanotify_init, unsigned int, flags, unsigned int, event_f_flags) } group->fanotify_data.user = user; + group->fanotify_data.should_report_tid = (flags & FAN_EVENT_INFO_TID) ? true : false; atomic_inc(&user->fanotify_listeners); group->memcg = get_mem_cgroup_from_mm(current->mm); diff --git a/include/linux/fsnotify_backend.h b/include/linux/fsnotify_backend.h index b8f4182..44c659f 100644 --- a/include/linux/fsnotify_backend.h +++ b/include/linux/fsnotify_backend.h @@ -193,6 +193,7 @@ struct fsnotify_group { unsigned int max_marks; struct user_struct *user; bool audit; + bool should_report_tid; } fanotify_data; #endif /* CONFIG_FANOTIFY */ }; diff --git a/include/uapi/linux/fanotify.h b/include/uapi/linux/fanotify.h index 7424791..4eba41c 100644 --- a/include/uapi/linux/fanotify.h +++ b/include/uapi/linux/fanotify.h @@ -18,6 +18,7 @@ #define FAN_ONDIR 0x40000000 /* event occurred against dir */ +#define FAN_EVENT_INFO_TID 0x02000000 /* reports the thread id of the event trigger */ #define FAN_EVENT_ON_CHILD 0x08000000 /* interested in child events */ /* helper events */ -- 2.10.1