From: Jeff Layton <jlayton@kernel.org>
To: 黄思聪 <huangsicong@iie.ac.cn>, chuck.lever@oracle.com
Cc: neilb@suse.de, kolga@netapp.com, Dai.Ngo@oracle.com,
tom@talpey.com, linux-nfs@vger.kernel.org
Subject: Re: PROBLEM: Pointer dereference error may occur in "alloc_init_deleg" function
Date: Wed, 11 Oct 2023 08:16:14 -0400 [thread overview]
Message-ID: <168b769e12553d9a5974943f523de2f8b903d61b.camel@kernel.org> (raw)
In-Reply-To: <49ad6b84.57cc.18b1de7572b.Coremail.huangsicong@iie.ac.cn>
On Wed, 2023-10-11 at 16:43 +0800, 黄思聪 wrote:
> Pointer dereference error may occur in "alloc_init_deleg" function.
>
> The "alloc_init_deleg" function located in "fs/nfsd/nfs4state.c" may occur a pointer dereference error when it calls the function "nfs4_alloc_stid" located in the same kernel file. The "nfs4_alloc_stid" function will call the "kmem_cache_zalloc" function to allocate enough memory for storing the "stid" variable. If there are significant memory fragmentation issues, insufficient free memory blocks, or internal errors in the allocation function, the "kmem_cache_zalloc" function will return NULL. Then the "nfs4_alloc_stid" function will return NULL to the "alloc_init_deleg" function. Finally, the "alloc_init_deleg" function will execute the following instructions.
> dp = delegstateid(nfs4_alloc_stid(clp, deleg_slab, nfs4_free_deleg));
> if (dp == NULL)
> goto out_dec;
> dp->dl_stid.sc_stateid.si_generation = 1;
>
> The "delegstateid" function is defined as below:
> static inline struct nfs4_delegation *delegstateid(struct nfs4_stid *s)
> {
> return container_of(s, struct nfs4_delegation, dl_stid);
> }
>
> When the parameter "struct nfs4_stid *s" is NULL, the function will return a strange value which is a negative number. The value will be interpreted as a very large number. Then the variable "dp" in the "alloc_init_deleg" function will get the value, and it will pass the following "if" conditional statements. In the last, the variable "dp" will be dereferenced, and it will cause an error.
>
> My experimental kernel version is "LINUX 6.1", and this problem exists in all the version from "LINUX v3.2-rc1" to "LINUX v6.6-rc5".
(I don't think there are security implications here, so I'm cc'ing the
mailing list and making this public.)
Well spotted! Ordinarily you'd be correct, but dl_stid is the first
field in the struct, so the container_of will just return the same
value that you pass in.
Still, this is not something we ought to rely on going forward. Would
you care to make a patch to clean this up and make that a bit less
subtle?
Thanks!
--
Jeff Layton <jlayton@kernel.org>
next parent reply other threads:[~2023-10-11 12:16 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <49ad6b84.57cc.18b1de7572b.Coremail.huangsicong@iie.ac.cn>
2023-10-11 12:16 ` Jeff Layton [this message]
2023-10-12 8:34 ` [PATCH v1] NFSD: clean up alloc_init_deleg() 黄思聪
2023-10-12 12:26 ` Chuck Lever III
2023-10-12 12:44 ` Jeff Layton
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=168b769e12553d9a5974943f523de2f8b903d61b.camel@kernel.org \
--to=jlayton@kernel.org \
--cc=Dai.Ngo@oracle.com \
--cc=chuck.lever@oracle.com \
--cc=huangsicong@iie.ac.cn \
--cc=kolga@netapp.com \
--cc=linux-nfs@vger.kernel.org \
--cc=neilb@suse.de \
--cc=tom@talpey.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