Igt-dev Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Jonathan Cavitt <jonathan.cavitt@intel.com>
To: igt-dev@lists.freedesktop.org
Cc: jonathan.cavitt@intel.com, saurabhg.gupta@intel.com,
	alex.zuo@intel.com, sai.gowtham.ch@intel.com
Subject: [PATCH] lib/xe/xe_gt: Guard against fopen failure in xe_gt_stats_get_count
Date: Tue,  3 Dec 2024 20:26:00 +0000	[thread overview]
Message-ID: <20241203202600.56749-1-jonathan.cavitt@intel.com> (raw)

The function xe_gt_stats_get_count currently performs an fopen on the
/sys/kernel/debug/dri/0/gt*/stats directory without checking that the
fopen is successful.  This can cause a system crash when trying to
perform fgets on a NULL pointer on unsuccessful cases.

Check the results of fopen and guard against this.

Closes: https://gitlab.freedesktop.org/drm/xe/kernel/-/issues/3212
Signed-off-by: Jonathan Cavitt <jonathan.cavitt@intel.com>
---
 lib/xe/xe_gt.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/lib/xe/xe_gt.c b/lib/xe/xe_gt.c
index cee892af96..101b887a41 100644
--- a/lib/xe/xe_gt.c
+++ b/lib/xe/xe_gt.c
@@ -159,6 +159,8 @@ int xe_gt_stats_get_count(int fd, int gt, const char *stat)
 	sprintf(path, "/sys/kernel/debug/dri/0/gt%d/stats", gt);
 	f = fopen(path, "r");
 
+	igt_assert_f(f, "Failed to open /sys/kernel/debug/dri/0/gt%d/stats", gt);
+
 	while (fgets(tlb_path, sizeof(tlb_path), f)) {
 		if (strstr(tlb_path, stat) != NULL) {
 			sscanf(tlb_path, "%*[^:]: %d", &count);
-- 
2.43.0


             reply	other threads:[~2024-12-03 20:26 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-12-03 20:26 Jonathan Cavitt [this message]
2024-12-03 22:23 ` ✓ i915.CI.BAT: success for lib/xe/xe_gt: Guard against fopen failure in xe_gt_stats_get_count Patchwork
2024-12-03 22:43 ` ✓ Xe.CI.BAT: " Patchwork
2024-12-03 23:47 ` ✗ Xe.CI.Full: failure " Patchwork
2024-12-04 15:00   ` Cavitt, Jonathan
2024-12-03 23:48 ` ✗ i915.CI.Full: " Patchwork
2024-12-04 15:00   ` Cavitt, Jonathan
2024-12-04 12:51 ` [PATCH] " Kamil Konieczny

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=20241203202600.56749-1-jonathan.cavitt@intel.com \
    --to=jonathan.cavitt@intel.com \
    --cc=alex.zuo@intel.com \
    --cc=igt-dev@lists.freedesktop.org \
    --cc=sai.gowtham.ch@intel.com \
    --cc=saurabhg.gupta@intel.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox