From patchwork Wed Apr 20 20:43:02 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Hostetler X-Patchwork-Id: 12820802 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3A00FC433FE for ; Wed, 20 Apr 2022 20:44:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1382194AbiDTUqt (ORCPT ); Wed, 20 Apr 2022 16:46:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58534 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1382158AbiDTUq0 (ORCPT ); Wed, 20 Apr 2022 16:46:26 -0400 Received: from mail-wm1-x32d.google.com (mail-wm1-x32d.google.com [IPv6:2a00:1450:4864:20::32d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4A7813EB94 for ; Wed, 20 Apr 2022 13:43:38 -0700 (PDT) Received: by mail-wm1-x32d.google.com with SMTP id x3so1959613wmj.5 for ; Wed, 20 Apr 2022 13:43:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=5W2x8t68NoDAVIFeMr0BVtQdXxzEzVw8wanSKIA/+K4=; b=SOj+zjBvBhMGGNdaGo/b+v8qD7SNB0a3h9lauVK2Q1fWNxzLsUEjkVtHAjWvzOO9m1 dCphtGoLQ5Mr7yGTS0P9TsgBOliQuy6JCXDAYy/6xidSLFPwYPnTcgUPsnl7J/RKd5d8 8WAESZmzlIXvnfKNW7cAJPE3Wo9i2NSgde79t7/hxZ8Z6Dcqn3w180/cdQaJcDVpX03v z3Vog+qX+bEzzpTxCYo/zleDeUaBuecOxmE1xZrDklnbIspfQEpAMOOAKTCxnLGygDN0 fmAttQtyUlB5HhQziqYE1eVJ+KiBcMKEGnsO1dDf+DENw7PlBvyYgNSVxUC5CJAbCmkN B74g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=5W2x8t68NoDAVIFeMr0BVtQdXxzEzVw8wanSKIA/+K4=; b=SLGwV40Jfr6X9drgwIursaDxg4okuMfv8Jl4RgxklRImBNDYQEsVxpR/pJLIuEWYtg RISJQJJqPY9W8wLZes1Vtr3f+g627/UUHyeTI5lUvgGSyfxotZVpsNg8nd9s0Zdi70Jb TB/ObiiSEtcswZ1+r6PjS0x/VSGudfekKENFG3bFFV3S8hiox2ummFX2lFlokRMlrL4m wPwZqzv5zteeUgSEARles5MB2Dga70qQE+xEzuivJMtVhaMm56/CNVfpZn0RhV73dX5x ePTdIFQJrr8oG7Zw4WpNXVxvuLsI4Vwbca/6HLKEqUWJGtavr++xLwAN5BHSKEuaAjXK yjNw== X-Gm-Message-State: AOAM5307kl4jvZ2OhQUmFDkemYaPjEE6VOS1opPjBKyVvWKyU3yv0kGL czuDaUnZUAOKpfajInkY8tuuqjK/Ci4= X-Google-Smtp-Source: ABdhPJz1Sq5zEGC2caOn3aZZX7eaDXHFzej8szRrx71bTgz+Ir/npipQKt4crPcD5KMlbCDeUOYtPw== X-Received: by 2002:a1c:35c2:0:b0:38e:c75d:90a3 with SMTP id c185-20020a1c35c2000000b0038ec75d90a3mr5320831wma.98.1650487416582; Wed, 20 Apr 2022 13:43:36 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id i6-20020a0560001ac600b0020a93f75030sm694539wry.48.2022.04.20.13.43.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Apr 2022 13:43:35 -0700 (PDT) Message-Id: <088c7b3334c79679d605dd16dc90211c08320428.1650487399.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Wed, 20 Apr 2022 20:43:02 +0000 Subject: [PATCH v5 12/28] fsm-listen-darwin: ignore FSEvents caused by xattr changes on macOS Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Jeff Hostetler , Derrick Stolee , =?utf-8?b?w4Z2YXIgQXJuZmrDtnI=?= =?utf-8?b?w7A=?= Bjarmason , Torsten =?unknown-8bit?q?B?= =?unknown-8bit?q?=C3=B6gershausen?= , rsbecker@nexbridge.com, Bagas Sanjaya , Jeff Hostetler , Jeff Hostetler Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Jeff Hostetler From: Jeff Hostetler Ignore FSEvents resulting from `xattr` changes. Git does not care about xattr's or changes to xattr's, so don't waste time collecting these events in the daemon nor transmitting them to clients. Various security tools add xattrs to files and/or directories, such as to mark them as having been downloaded. We should ignore these events since it doesn't affect the content of the file/directory or the normal meta-data that Git cares about. Signed-off-by: Jeff Hostetler --- compat/fsmonitor/fsm-listen-darwin.c | 34 +++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/compat/fsmonitor/fsm-listen-darwin.c b/compat/fsmonitor/fsm-listen-darwin.c index 0741fe834c3..14105f45c18 100644 --- a/compat/fsmonitor/fsm-listen-darwin.c +++ b/compat/fsmonitor/fsm-listen-darwin.c @@ -100,7 +100,7 @@ static void log_flags_set(const char *path, const FSEventStreamEventFlags flag) if (flag & kFSEventStreamEventFlagItemCloned) strbuf_addstr(&msg, "ItemCloned|"); - trace_printf_key(&trace_fsmonitor, "fsevent: '%s', flags=%u %s", + trace_printf_key(&trace_fsmonitor, "fsevent: '%s', flags=0x%x %s", path, flag, msg.buf); strbuf_release(&msg); @@ -125,6 +125,31 @@ static int ef_is_dropped(const FSEventStreamEventFlags ef) ef & kFSEventStreamEventFlagUserDropped); } +/* + * If an `xattr` change is the only reason we received this event, + * then silently ignore it. Git doesn't care about xattr's. We + * have to be careful here because the kernel can combine multiple + * events for a single path. And because events always have certain + * bits set, such as `ItemIsFile` or `ItemIsDir`. + * + * Return 1 if we should ignore it. + */ +static int ef_ignore_xattr(const FSEventStreamEventFlags ef) +{ + static const FSEventStreamEventFlags mask = + kFSEventStreamEventFlagItemChangeOwner | + kFSEventStreamEventFlagItemCreated | + kFSEventStreamEventFlagItemFinderInfoMod | + kFSEventStreamEventFlagItemInodeMetaMod | + kFSEventStreamEventFlagItemModified | + kFSEventStreamEventFlagItemRemoved | + kFSEventStreamEventFlagItemRenamed | + kFSEventStreamEventFlagItemXattrMod | + kFSEventStreamEventFlagItemCloned; + + return ((ef & mask) == kFSEventStreamEventFlagItemXattrMod); +} + static void fsevent_callback(ConstFSEventStreamRef streamRef, void *ctx, size_t num_of_events, @@ -190,6 +215,13 @@ static void fsevent_callback(ConstFSEventStreamRef streamRef, continue; } + if (ef_ignore_xattr(event_flags[k])) { + trace_printf_key(&trace_fsmonitor, + "ignore-xattr: '%s', flags=0x%x", + path_k, event_flags[k]); + continue; + } + switch (fsmonitor_classify_path_absolute(state, path_k)) { case IS_INSIDE_DOT_GIT_WITH_COOKIE_PREFIX: