AMD-GFX Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Niels Dossche <dossche.niels@gmail.com>
To: amd-gfx@lists.freedesktop.org
Cc: "Alex Deucher" <alexander.deucher@amd.com>,
	"Pan, Xinhui" <Xinhui.Pan@amd.com>,
	"Niels Dossche" <dossche.niels@gmail.com>,
	"Christian König" <christian.koenig@amd.com>
Subject: [RFC PATCH] drm/amdgpu: fix EFAULT return value for debugfs ctrl parse data
Date: Fri, 29 Apr 2022 23:29:04 +0200	[thread overview]
Message-ID: <20220429212904.83002-1-dossche.niels@gmail.com> (raw)

amdgpu_ras_debugfs_ctrl_parse_data is reachable from a debug fs write.
A write is supposed to return EFAULT when the user buffer is outside
the address space. Right now it returns EINVAL.
Change the EINVAL to EFAULT.

Fixes: 96ebb3073275 ("drm/amdgpu: add human readable debugfs control support (v2)")
Signed-off-by: Niels Dossche <dossche.niels@gmail.com>
---

I found this issue using static analysis to find inconsistent error
handling regarding kernel APIs. Found on v5.17.4.
As I do not have the necessary hardware, I only managed to compile test
this on x86_64. I put this as an RFC as I'm a bit worried about possible
userspace API breakage that might rely on the EINVAL behaviour.

 drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c
index 424c22a841f4..9bbdf0519c31 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c
@@ -253,7 +253,7 @@ static int amdgpu_ras_debugfs_ctrl_parse_data(struct file *f,
 	memset(data, 0, sizeof(*data));
 
 	if (copy_from_user(str, buf, s))
-		return -EINVAL;
+		return -EFAULT;
 
 	if (sscanf(str, "disable %32s", block_name) == 1)
 		op = 0;
@@ -308,7 +308,7 @@ static int amdgpu_ras_debugfs_ctrl_parse_data(struct file *f,
 			return -EINVAL;
 
 		if (copy_from_user(data, buf, sizeof(*data)))
-			return -EINVAL;
+			return -EFAULT;
 	}
 
 	return 0;
-- 
2.35.2


                 reply	other threads:[~2022-05-02 13:00 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20220429212904.83002-1-dossche.niels@gmail.com \
    --to=dossche.niels@gmail.com \
    --cc=Xinhui.Pan@amd.com \
    --cc=alexander.deucher@amd.com \
    --cc=amd-gfx@lists.freedesktop.org \
    --cc=christian.koenig@amd.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