All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Xin Tian" <tianx@yunsilicon.com>
Cc: linux-rdma@vger.kernel.org
Subject: Re: [PATCH 14/15] yunsilicon: add RDMA counters and sysfs
Date: Tue, 13 Oct 2026 11:46:15 +0000	[thread overview]
Message-ID: <sashiko-outbox-169652@kernel.org> (raw)
In-Reply-To: <20261012114425.2471317-15-tianx@yunsilicon.com>

Thank you for your contribution! Sashiko AI review found 4 potential issue(s) to consider:
- [High] sysfs: kobject UAF via missing .release and synchronous kfree
- [High] sysfs: global singleton g_global_cnt_interface corrupts multi-device state
- [Medium] sysfs: counters_value_read breaks partial reads and ignores offset
- [Medium] infiniband: sysfs attribute creation races with udev KOBJ_ADD
--

commit e407716ecbb78f776fbe73fcb02888c7ab5c00c8
Author: Xin Tian <tianx@yunsilicon.com>

yunsilicon: add RDMA counters and sysfs

This commit adds hardware counter reporting through the RDMA counter
interface, global counter sysfs attributes, and hca_type/hw_rev sysfs
attributes.

> diff --git a/drivers/infiniband/hw/xsc/counters.c b/drivers/infiniband/hw/xsc/counters.c
> new file mode 100644
> index 0000000000000..135df95954a75
> --- /dev/null
> +++ b/drivers/infiniband/hw/xsc/counters.c
[ ... ]
> +static ssize_t counters_value_read(struct file *file, struct kobject *kob,
> +				   const struct bin_attribute *bin_attr,
> +				   char *buf, loff_t loff, size_t size)
> +{
[ ... ]
> +	if (bin_attr->size > size || bin_attr->size == 0)
> +		return 0;

[Severity: Medium]
Does this check incorrectly reject partial or offset-bounded reads? 

Since the sysfs core bounds the requested size to max_size - loff, a read
with a non-zero offset or a user buffer smaller than bin_attr->size might
immediately fail with an early EOF here.

[ ... ]
> +	mask = xsc_get_rdma_stat_mask(xdev, be16_to_cpu(stats_rdma.ver));
> +	j = 0;
> +	for (i = 0; i < desc_size; i++) {
> +		if (!((1ULL << i) & mask))
> +			continue;
> +		tmp_value[j] = be64_to_cpu(*(u64 *)(stats + desc[i].offset));
> +		j++;
> +	}
> +
> +	memcpy(buf, tmp_value, bin_attr->size);
> +
> +	kfree(tmp_value);
> +	return bin_attr->size;
> +}

[Severity: Medium]
Could this ignore the requested offset during a read?

The loff parameter is not used in the memcpy() call, so if a read succeeded
at a non-zero offset, it would incorrectly copy from the beginning of
tmp_value instead of applying the requested offset.

[ ... ]
> +static const struct kobj_type global_cnt_ktype = {
> +	.sysfs_ops     = &global_cnt_sysfs_ops,
> +	.default_groups = global_cnt_groups,
> +};

[Severity: High]
Is this kobj_type missing the mandatory .release callback required for
kobjects? 

Without it, the kobject container memory cannot be safely managed when the
reference count reaches zero.

> +
> +static struct xsc_global_cnt_interface *g_global_cnt_interface;
> +
> +static int global_cnt_sysfs_init(struct ib_device *ib_dev, struct xsc_core_device *xdev)
> +{
[ ... ]
> +	err = kobject_init_and_add(&tmp->kobj, &global_cnt_ktype,
> +				   &ib_dev->dev.kobj, GLOBAL_COUNTERS_GROUP_NAME);
> +	if (err)
> +		goto error_return;
> +
> +	g_global_cnt_interface = tmp;
> +	tmp->xdev = xdev;
> +	return 0;

[Severity: High]
Does this blindly overwrite the global pointer g_global_cnt_interface for
every initialized physical function?

If the system contains multiple Yunsilicon network adapters, initializing the
second one would overwrite the pointer. This would lose the previous device's
state and permanently leak its memory and kobject. Furthermore, removing the
first device would cause global_cnt_sysfs_fini() to mistakenly operate on the
second device's state.

[ ... ]
> +static void global_cnt_sysfs_fini(struct xsc_core_device *xdev)
> +{
> +	if (!g_global_cnt_interface || !xdev || !xsc_core_is_pf(xdev) || xdev->pf_id != 0)
> +		return;
> +
> +	kobject_put(&g_global_cnt_interface->kobj);
> +	kfree(g_global_cnt_interface);
> +	g_global_cnt_interface = NULL;
> +}

[Severity: High]
Is it safe to synchronously free the kobject container memory here?

Since kobject_put() merely decrements the reference count, the kobject and
its sysfs representation could remain active if userspace still holds an
open file descriptor. Calling kfree() immediately afterwards destroys the
underlying memory prematurely, which might lead to a use-after-free crash
when userspace subsequently accesses the sysfs files.

> diff --git a/drivers/infiniband/hw/xsc/main.c b/drivers/infiniband/hw/xsc/main.c
> index 30927006bae2d..38c8b4f0690c2 100644
> --- a/drivers/infiniband/hw/xsc/main.c
> +++ b/drivers/infiniband/hw/xsc/main.c
[ ... ]
> @@ -745,7 +745,9 @@ static int init_one(struct xsc_core_device *xdev,
>  
>  	xsc_register_netdev_notifier(dev);
>  
> +	xsc_counters_init(&dev->ib_dev, xdev);
>  
> +	xsc_ib_sysfs_init(&dev->ib_dev, xdev);
>  
>  	return 0;

[Severity: Medium]
Does creating the sysfs attribute files here cause a race condition with
udev?

The driver registers the device earlier in init_one() by calling
ib_register_device(), which triggers a KOBJ_ADD uevent. Adding the sysfs
files after this registration means udev rules might execute before the
attributes actually exist. Should the sysfs groups be assigned to the
device's attribute groups (e.g., ib_dev->groups) prior to registration
instead?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261012114352.2471317-1-tianx@yunsilicon.com?part=14

  reply	other threads:[~2026-10-13 11:46 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-12 11:44 [PATCH 00/15] Yunsilicon ethernet and RDMA drivers Xin Tian
2026-10-12 11:43 ` [PATCH 01/15] yunsilicon: add PCI core driver skeleton Xin Tian
2026-10-13 11:46   ` sashiko-bot
2026-10-12 11:43 ` [PATCH 02/15] yunsilicon: add the register HAL Xin Tian
2026-10-12 15:21   ` Andrew Lunn
2026-10-13 11:46   ` sashiko-bot
2026-10-12 11:43 ` [PATCH 03/15] yunsilicon: add the command queue Xin Tian
2026-10-13  3:11   ` Junxian Huang
2026-10-13 14:31     ` Leon Romanovsky
2026-10-13 11:46   ` sashiko-bot
2026-10-12 11:44 ` [PATCH 04/15] yunsilicon: add event queues, interrupts and the Xin Tian
2026-10-13 11:46   ` sashiko-bot
2026-10-12 11:44 ` [PATCH 05/15] yunsilicon: add the CQ and QP resource pools Xin Tian
2026-10-13 11:46   ` sashiko-bot
2026-10-12 11:44 ` [PATCH 06/15] yunsilicon: add ethernet netdev registration Xin Tian
2026-10-13 11:46   ` sashiko-bot
2026-10-12 11:44 ` [PATCH 07/15] yunsilicon: add ethernet TX path Xin Tian
2026-10-13 11:46   ` sashiko-bot
2026-10-12 11:44 ` [PATCH 08/15] yunsilicon: add ethernet RX path and statistics Xin Tian
2026-10-13 11:46   ` sashiko-bot
2026-10-12 11:44 ` [PATCH 09/15] yunsilicon: add RDMA device support Xin Tian
2026-10-13  6:17   ` Junxian Huang
2026-10-13 11:46   ` sashiko-bot
2026-10-12 11:44 ` [PATCH 10/15] yunsilicon: add RDMA PD/MR Xin Tian
2026-10-13 11:46   ` sashiko-bot
2026-10-12 11:44 ` [PATCH 11/15] yunsilicon: add RDMA CQ/SRQ/AH Xin Tian
2026-10-13 11:46   ` sashiko-bot
2026-10-12 11:44 ` [PATCH 12/15] yunsilicon: add RDMA QP verbs Xin Tian
2026-10-13 11:46   ` sashiko-bot
2026-10-12 11:44 ` [PATCH 13/15] yunsilicon: add the RDMA send path Xin Tian
2026-10-13 11:46   ` sashiko-bot
2026-10-12 11:44 ` [PATCH 14/15] yunsilicon: add RDMA counters and sysfs Xin Tian
2026-10-13 11:46   ` sashiko-bot [this message]
2026-10-12 11:44 ` [PATCH 15/15] MAINTAINERS: add the Yunsilicon XSC drivers Xin Tian
2026-10-13 14:34 ` [PATCH 00/15] Yunsilicon ethernet and RDMA drivers Leon Romanovsky

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=sashiko-outbox-169652@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=linux-rdma@vger.kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=tianx@yunsilicon.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.