public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: "Huang, Ying" <ying.huang@linux.alibaba.com>
To: kingdix10@qq.com
Cc: akpm@linux-foundation.org,  andriy.shevchenko@linux.intel.com,
	ilpo.jarvinen@linux.intel.com,  bhelgaas@google.com,
	mika.westerberg@linux.intel.com,  huang.ying.caritas@gmail.com,
	jhubbard@nvidia.com,  peterz@infradead.org,
	 linux-kernel@vger.kernel.org
Subject: Re: [PATCH] resource: use kstrdup_const to prevent wild pointer issues
Date: Thu, 02 Jan 2025 09:59:26 +0800	[thread overview]
Message-ID: <87seq2dlhd.fsf@DESKTOP-5N7EMDA> (raw)
In-Reply-To: <tencent_3BD5C192A0E62121DE44D1A05A9C9ECB7C06@qq.com> (kingdix's message of "Wed, 1 Jan 2025 21:49:08 +0800")

kingdix10@qq.com writes:

> From: King Dix <kingdix10@qq.com>
>
> When a stack string variable is passed during the request resource
> operation, it causes an oops problem when executing cat /proc/iomem.
>
> In the original code, in functions like __request_region_locked, the name
> member of the resource structure was directly assigned the stack string
> pointer without proper memory management.
>
> This fix changes the assignment of res->name to use kstrdup_const for
> string copying, ensuring the correct storage and release of the string
> and thus avoiding potential memory errors and oops issues.
>
> Signed-off-by: King Dix <kingdix10@qq.com>

In general, I think that it's good to improve the resource requesting
API.  However, it's not good to use so many GFP_ATOMIC too.  Why do you
need to call resource requesting API with stack variable?  If it's just
some programming bugs, we should add more checks instead of hiding the
bugs.  For example, if we only allows kernel rodata and slab memory to be
used in resource requesting.  We can add a VM_WARN_ON() to check that.

[snip]

---
Best Regards,
Huang, Ying

  reply	other threads:[~2025-01-02  1:59 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-01-01 13:49 [PATCH] resource: use kstrdup_const to prevent wild pointer issues kingdix10
2025-01-02  1:59 ` Huang, Ying [this message]
2025-01-02 23:33   ` Andrew Morton
2025-01-03  8:38 ` kernel test robot

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=87seq2dlhd.fsf@DESKTOP-5N7EMDA \
    --to=ying.huang@linux.alibaba.com \
    --cc=akpm@linux-foundation.org \
    --cc=andriy.shevchenko@linux.intel.com \
    --cc=bhelgaas@google.com \
    --cc=huang.ying.caritas@gmail.com \
    --cc=ilpo.jarvinen@linux.intel.com \
    --cc=jhubbard@nvidia.com \
    --cc=kingdix10@qq.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mika.westerberg@linux.intel.com \
    --cc=peterz@infradead.org \
    /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