From: Andrew Morton <akpm@linux-foundation.org>
To: "Huang, Ying" <ying.huang@linux.alibaba.com>
Cc: kingdix10@qq.com, 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, 2 Jan 2025 15:33:59 -0800 [thread overview]
Message-ID: <20250102153359.0bb10b8bb0d4293a935c4a3a@linux-foundation.org> (raw)
In-Reply-To: <87seq2dlhd.fsf@DESKTOP-5N7EMDA>
On Thu, 02 Jan 2025 09:59:26 +0800 "Huang, Ying" <ying.huang@linux.alibaba.com> wrote:
> > 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.
I agree. It may not be a very good idea, but request_region() requires
that the caller pass in a `name' string which is permanently available.
__request_region() kerneldoc doesn't document this, and it should.
Because of this present interface design, calling request_region() with
an on-stack string must be considered a bug in the calling code.
next prev parent reply other threads:[~2025-01-02 23:34 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-01-01 13:49 kingdix10
2025-01-02 1:59 ` Huang, Ying
2025-01-02 23:33 ` Andrew Morton [this message]
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=20250102153359.0bb10b8bb0d4293a935c4a3a@linux-foundation.org \
--to=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 \
--cc=ying.huang@linux.alibaba.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
all inboxes | Powered by JetHome®