Received: by 2002:a05:7412:8d11:b0:fa:4934:9f with SMTP id bj17csp411000rdb; Mon, 15 Jan 2024 00:57:07 -0800 (PST) X-Google-Smtp-Source: AGHT+IGXNUlQOgU/DSqkp5tW2C+dZR+fQ/lOKl7o7n9jpwIQouoD+yL1oTGY2X50Nuky+NBE2mgz X-Received: by 2002:a17:902:d4c7:b0:1d4:4a0e:72a with SMTP id o7-20020a170902d4c700b001d44a0e072amr2833376plg.93.1705309027685; Mon, 15 Jan 2024 00:57:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1705309027; cv=none; d=google.com; s=arc-20160816; b=JeL5DpYrsSVNdA/zrF0U6tAeRXf7GbXg2/jjmgjIZkjrWTtg+yFHTvYz2cJN/JBJn4 zgg3QPlLeQvYR8yfDmotlq4iY+g6A9wIia8UI1BZVIzQGnvQNly+7ZtgLFjiv0LTW1or 8m6R6uNXdDN8l4RuFfUroIMhrgh79cpNB9kOwBovzGc/bZzBPedyqiydA3Kjb131DTYp jE1De+opmFnXIP03536REHg1aV782tstT+uzFyX3a/lMl47cb0g4pJzjaZIiCnMWAw4B Fl/M/XhKq6FbevCkxHtuhTwYD1NB+azJYVNL31lkv8gp5mDHx/LAyqhzKJ3rNP7A8TBp kvww== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=HNnj9fTgsU6ypQaGbjnHmvoqu4dzt21ypwIIk71/a6Y=; fh=0F13UeAhzsczpFrpCDJCrcHCMbTWAMKB9mHJhoEEaGg=; b=W44XTzsC5kZB0mufZdizRFUMwz8smAQ4UKlIoJ0cyW/Mo5IoiCj0dpMGc9BbCfW4By Gaaft/MNPbuKVHuWdHFvOivpsuNMfZa+C63ZQ/JIwjni/Wgzf+IrNHzOHDSEB2/dIqWW J6WktjxxCpweM+E2uXYgpRzVCWRGrbUmtrbo4ZYIprBwL4pBZnRWeknDnmGVKmvd3nEP +VmeB4qaDhmF6RTcSCy1q3mtAHDfkZbg0a12sWUm9pkHwqdhPL8Ybw4Waw6yNE5qx0PB AABta8asp724dIqYz8yYAnVyqa7EGjm4np7VPoJUMJ1eleJEzT3ZNgg8CR7+L5bdBiJw Ul0A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=MvDD6KWa; spf=pass (google.com: domain of linux-kernel+bounces-25760-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-25760-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id o12-20020a17090323cc00b001d40ca98b6esi8231640plh.8.2024.01.15.00.57.07 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 Jan 2024 00:57:07 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-25760-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=MvDD6KWa; spf=pass (google.com: domain of linux-kernel+bounces-25760-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-25760-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 26741281D10 for ; Mon, 15 Jan 2024 08:57:07 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E868710958; Mon, 15 Jan 2024 08:55:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="MvDD6KWa" Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.43]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B5C0DF51E; Mon, 15 Jan 2024 08:55:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1705308954; x=1736844954; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=zPtD/bN19IJuSWVPo1+D4i+VRget/n6bfsyISYsUZb4=; b=MvDD6KWaw4uQPK8CNQK29H1W8IzuskOhUUmXvsyMY3xw8mi9K2k4zlpS wIDJF850EqiWfrmgCsPStLaGIHEFCCS5G3hGdi5Zm/+WEjIQZ699CbzgJ IL+KiShoydLIeTGg1VBLvGFDHizd5tliWDxKMexAhAmmnkbP2z1ttjRlL GJ0/T0L+22KIN9ayTDfsULY+N82v9nVZeXIstXU7RGL7h3SgDtlXjsybq emimSDVPdeuQbGhslC7OGkpcpNBPogfPqfhVYTjne9eFrW+0ZZIWTajjn JZSFJWmTvlbCSXee/ct/ypggpwgR82rVMZcu9rCEImshtziXHPXE/AFDx g==; X-IronPort-AV: E=McAfee;i="6600,9927,10953"; a="485728197" X-IronPort-AV: E=Sophos;i="6.04,196,1695711600"; d="scan'208";a="485728197" Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 Jan 2024 00:55:54 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10953"; a="853935196" X-IronPort-AV: E=Sophos;i="6.04,196,1695711600"; d="scan'208";a="853935196" Received: from amlin-018-114.igk.intel.com ([10.102.18.114]) by fmsmga004.fm.intel.com with ESMTP; 15 Jan 2024 00:55:51 -0800 From: Arkadiusz Kubalewski To: netdev@vger.kernel.org Cc: vadim.fedorenko@linux.dev, jiri@resnulli.us, davem@davemloft.net, milena.olech@intel.com, linux-kernel@vger.kernel.org, pabeni@redhat.com, kuba@kernel.org, mschmidt@redhat.com, Arkadiusz Kubalewski , Jan Glaza Subject: [PATCH net v3 3/3] dpll: fix userspace availability of pins Date: Mon, 15 Jan 2024 09:52:41 +0100 Message-Id: <20240115085241.312144-4-arkadiusz.kubalewski@intel.com> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20240115085241.312144-1-arkadiusz.kubalewski@intel.com> References: <20240115085241.312144-1-arkadiusz.kubalewski@intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit If parent pin was unregistered but child pin was not, the userspace would see the "zombie" pins - the ones that were registered with a parent pin (dpll_pin_on_pin_register(..)). Technically those are not available - as there is no dpll device in the system. Do not dump those pins and prevent userspace from any interaction with them. Provide a unified function to determine if the pin is available and use it before acting/responding for user requests. Fixes: 9431063ad323 ("dpll: core: Add DPLL framework base functions") Fixes: 9d71b54b65b1 ("dpll: netlink: Add DPLL framework base functions") Reviewed-by: Jan Glaza Signed-off-by: Arkadiusz Kubalewski --- v3: - introduce separated function to determine pin availability - move check for pin availablity to dpll_pin_pre_doit(..) - check if pin available within pin-id-get flow - rename patch title drivers/dpll/dpll_netlink.c | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/drivers/dpll/dpll_netlink.c b/drivers/dpll/dpll_netlink.c index 108c002537e6..7cc99d627942 100644 --- a/drivers/dpll/dpll_netlink.c +++ b/drivers/dpll/dpll_netlink.c @@ -525,6 +525,24 @@ __dpll_device_change_ntf(struct dpll_device *dpll) return dpll_device_event_send(DPLL_CMD_DEVICE_CHANGE_NTF, dpll); } +static bool dpll_pin_available(struct dpll_pin *pin) +{ + struct dpll_pin_ref *par_ref; + unsigned long i; + + if (!xa_get_mark(&dpll_pin_xa, pin->id, DPLL_REGISTERED)) + return false; + xa_for_each(&pin->parent_refs, i, par_ref) + if (xa_get_mark(&dpll_pin_xa, par_ref->pin->id, + DPLL_REGISTERED)) + return true; + xa_for_each(&pin->dpll_refs, i, par_ref) + if (xa_get_mark(&dpll_device_xa, par_ref->dpll->id, + DPLL_REGISTERED)) + return true; + return false; +} + /** * dpll_device_change_ntf - notify that the dpll device has been changed * @dpll: registered dpll pointer @@ -551,7 +569,7 @@ dpll_pin_event_send(enum dpll_cmd event, struct dpll_pin *pin) int ret = -ENOMEM; void *hdr; - if (!xa_get_mark(&dpll_pin_xa, pin->id, DPLL_REGISTERED)) + if (!dpll_pin_available(pin)) return -ENODEV; msg = genlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL); @@ -1102,6 +1120,10 @@ int dpll_nl_pin_id_get_doit(struct sk_buff *skb, struct genl_info *info) } pin = dpll_pin_find_from_nlattr(info); if (!IS_ERR(pin)) { + if (!dpll_pin_available(pin)) { + nlmsg_free(msg); + return -ENODEV; + } ret = dpll_msg_add_pin_handle(msg, pin); if (ret) { nlmsg_free(msg); @@ -1151,6 +1173,8 @@ int dpll_nl_pin_get_dumpit(struct sk_buff *skb, struct netlink_callback *cb) xa_for_each_marked_start(&dpll_pin_xa, i, pin, DPLL_REGISTERED, ctx->idx) { + if (!dpll_pin_available(pin)) + continue; hdr = genlmsg_put(skb, NETLINK_CB(cb->skb).portid, cb->nlh->nlmsg_seq, &dpll_nl_family, NLM_F_MULTI, @@ -1413,7 +1437,8 @@ int dpll_pin_pre_doit(const struct genl_split_ops *ops, struct sk_buff *skb, } info->user_ptr[0] = xa_load(&dpll_pin_xa, nla_get_u32(info->attrs[DPLL_A_PIN_ID])); - if (!info->user_ptr[0]) { + if (!info->user_ptr[0] || + !dpll_pin_available(info->user_ptr[0])) { NL_SET_ERR_MSG(info->extack, "pin not found"); ret = -ENODEV; goto unlock_dev; -- 2.38.1