Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp993206pxv; Thu, 22 Jul 2021 18:30:39 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwpvL4+epj+9q4sRxxPi2tWziWNs0ylU5Prh/gEkXf81jkCajZavXA9Lh/y1UnI2SmXwvec X-Received: by 2002:a50:ce45:: with SMTP id k5mr2837874edj.168.1627003838970; Thu, 22 Jul 2021 18:30:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1627003838; cv=none; d=google.com; s=arc-20160816; b=DafnzUqw0BfML2PHIhkI5XB8pdfjMw5f39YZGCcMk3vkn00jxGjoVyqKs+qlbmrwpd JoRB3lh7b5RYWbUoKksm6xnlKAa8aHHt4ntBjY14LAnkmiuRIqRbMt4PXsFEMnMwwH1S H50aJy7PTlL45pLVZ5+9qR9dDgr7NVlGrp+yBr1TMPz/onnvfh2mdRmYh3Ii0TUem/sZ XAVLQRiawdR8XUIbQpw22XKBo7weObbTR2CAjk2OWEA58hs0sS1wRAqo2tMpMTK+yKCQ +2MxQXhump6uZ1qmvbM6jMP1JPWs+N4+keHzRxG2jVcobeqa/6Xjczmhnt5hwRBYI3/q HPWw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:mime-version:message-id:date :dkim-signature; bh=Fn5O5gWOb6Ru+LgHgcwaMCAMb3hgNOKe/ej//OWLhcM=; b=kGhPEMVKB8/gN9UoRkyL111lGZSJnrr7fl5Vxqtis9bBXaiJY2xBYXermfwNlvM4Ui X2kdkJgax0izvAL19uKbLtk1YYEW0dxdiiYkbEh1eYfykgxgi/i5VuYGvmQLLBy0RKoT vr0+gqxNMAU378BOTiHexF/Hm+pI0IKQG9T/Pen34WCbCz2nGSiTy39OgXU7lc8XJ1NV tkNE+ka+BQItOX9GieRsOiQIRpNdWyYkCm9Id6H569iQlC64OmQ8LvvvEhtgFA/wCNKz /Jrpaiq1OighF6FQSgunFp3RlngKWDNhg69Kd2Xkg8JqMCtfYeBqv3o3xW0PES6VMqML Hetg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=SACaWiko; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id u26si33316581eda.447.2021.07.22.18.30.15; Thu, 22 Jul 2021 18:30:38 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=SACaWiko; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233095AbhGWAsG (ORCPT + 99 others); Thu, 22 Jul 2021 20:48:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55174 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232892AbhGWAsF (ORCPT ); Thu, 22 Jul 2021 20:48:05 -0400 Received: from mail-qv1-xf4a.google.com (mail-qv1-xf4a.google.com [IPv6:2607:f8b0:4864:20::f4a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0F4B4C061575 for ; Thu, 22 Jul 2021 18:28:40 -0700 (PDT) Received: by mail-qv1-xf4a.google.com with SMTP id b8-20020a0562141148b02902f1474ce8b7so734355qvt.20 for ; Thu, 22 Jul 2021 18:28:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:message-id:mime-version:subject:from:to:cc; bh=Fn5O5gWOb6Ru+LgHgcwaMCAMb3hgNOKe/ej//OWLhcM=; b=SACaWikoFPHWSTRsJ/h66/PZO6BUBliibjg3zOEZAYY7VRQaAW82XlbRTYz5A/JOha k/M7KnmITZ7HdVTF4UvNOEj68TJ1JSD+U20oqmhiJIe/dTBf5WZgc6nejCksKWED2ewO kHXYhB82pYLxnYV5NAT1CgUSZARRTvgAV3vF5Up+Hcxvj/vJLxn2oiyZglThnZAWfjrd 3PtDNgquIXrP9JmH6u4aq9fB7F9o9qdsnj1XLN1xJv7jY8ToLlDfQKnfQBhrgWDf4HPQ VjCWqyruBWEYdFzeU5vm41QLutmGIPsm8mzmlwZkAdZpAHx277xx1ek32QLJqVbhNOD8 MEjg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:message-id:mime-version:subject:from:to:cc; bh=Fn5O5gWOb6Ru+LgHgcwaMCAMb3hgNOKe/ej//OWLhcM=; b=ko7lpWVwe7ZbOAg52qQ91GF0kq9WgcbGyFMRavQELTJqiUw4dm77crz+P8SliyVjv5 VrpqR3cOLxlcyT7mVx9rMOkoQLddagJA6MeSj+QzK8aaB9tbyPfku3zx3ozdZgdhq9It 945MVfH23fcz9AnznWxkeGT79Hd0W6Qy0jlS/gyzqoPmHrmdOhkJvZEIKebtGGiQyEbC 0LR4kSXQKlOujDR3XdGM9cYO3PF95OSQBGfrjwIc8dFjenSDGpLqtvQD5HJgB5FWceWO soWMHxauolnM7zSe1rZVy0qmAGuxpSYIniU63b7et/+EjQh9TaHhdvebchaLQ8XZdGh0 aooQ== X-Gm-Message-State: AOAM532EuPHr1Rb/v0wNwmUAUubHQPVDzauTRq+Ctmh6k7HDSOJn/hpO rVE0LxcCtT9LXrBJR/akutWbOBzXyG9N X-Received: from rajat2.mtv.corp.google.com ([2620:15c:202:201:fdff:bbf6:d7ec:d92e]) (user=rajatja job=sendgmr) by 2002:a05:6214:767:: with SMTP id f7mr2583972qvz.16.1627003719133; Thu, 22 Jul 2021 18:28:39 -0700 (PDT) Date: Thu, 22 Jul 2021 18:28:34 -0700 Message-Id: <20210723012835.1935471-1-rajatja@google.com> Mime-Version: 1.0 X-Mailer: git-send-email 2.32.0.432.gabb21c7263-goog Subject: [PATCH] thunderbolt: For dev authorization changes, include the actual event in udev change notification From: Rajat Jain To: Andreas Noever , Michael Jamet , Mika Westerberg , Yehezkel Bernat , linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Rajat Jain , rajatxjain@gmail.com Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org For security, we would like to monitor and track when the thunderbolt devices are authorized and deauthorized. Currently the userspace gets a udev change notification when there is a change, but the state may have changed (again) by the time we look at the authorized attribute in sysfs. So an authorization event may go unnoticed. Thus make it easier by informing the actual change (authorized/deauthorized) in the udev change notification. Signed-off-by: Rajat Jain --- drivers/thunderbolt/switch.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/drivers/thunderbolt/switch.c b/drivers/thunderbolt/switch.c index 83b1ef3d5d03..5d3e9dcba44a 100644 --- a/drivers/thunderbolt/switch.c +++ b/drivers/thunderbolt/switch.c @@ -1499,6 +1499,7 @@ static ssize_t authorized_show(struct device *dev, static int disapprove_switch(struct device *dev, void *not_used) { struct tb_switch *sw; + char *envp[] = { "AUTHORIZED=0", NULL }; sw = tb_to_switch(dev); if (sw && sw->authorized) { @@ -1514,7 +1515,7 @@ static int disapprove_switch(struct device *dev, void *not_used) return ret; sw->authorized = 0; - kobject_uevent(&sw->dev.kobj, KOBJ_CHANGE); + kobject_uevent_env(&sw->dev.kobj, KOBJ_CHANGE, envp); } return 0; @@ -1523,6 +1524,8 @@ static int disapprove_switch(struct device *dev, void *not_used) static int tb_switch_set_authorized(struct tb_switch *sw, unsigned int val) { int ret = -EINVAL; + char envp_string[13]; + char *envp[] = { envp_string, NULL }; if (!mutex_trylock(&sw->tb->lock)) return restart_syscall(); @@ -1560,7 +1563,8 @@ static int tb_switch_set_authorized(struct tb_switch *sw, unsigned int val) if (!ret) { sw->authorized = val; /* Notify status change to the userspace */ - kobject_uevent(&sw->dev.kobj, KOBJ_CHANGE); + sprintf(envp_string, "AUTHORIZED=%u", val); + kobject_uevent_env(&sw->dev.kobj, KOBJ_CHANGE, envp); } unlock: -- 2.32.0.432.gabb21c7263-goog