From: Geliang Tang <geliangtang@gmail.com>
To: David Howells <dhowells@redhat.com>,
James Morris <jmorris@namei.org>,
"Serge E. Hallyn" <serge@hallyn.com>
Cc: keyrings@vger.kernel.org, linux-security-module@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH] security: keys: add NULL checking for key->type->instantiate
Date: Tue, 26 Feb 2019 17:09:03 +0800 [thread overview]
Message-ID: <20190226090903.GA3197@OptiPlex> (raw)
In-Reply-To: <31395.1549492013@warthog.procyon.org.uk>
On Wed, Feb 06, 2019 at 10:26:53PM +0000, David Howells wrote:
> Geliang Tang <geliangtang@gmail.com> wrote:
>
> > key->type->instantiate can be NULL, add NULL checking to prevent
> > NULL pointer dereference in __key_instantiate_and_link().
>
> Do you have an oops report or test case for this?
>
> David
Here is the test module code. Insmod it, we can get the oops.
#include <linux/init.h>
#include <linux/module.h>
#include <linux/key.h>
#include <linux/key-type.h>
#include <linux/cred.h>
#include <linux/seq_file.h>
static int test_instantiate(struct key *key, struct key_preparsed_payload *prep)
{
return 0;
}
static void test_describe(const struct key *key, struct seq_file *m)
{
seq_puts(m, key->description);
}
struct key_type test_key_type = {
.name = "test",
//.instantiate = test_instantiate,
.describe = test_describe,
};
static int __init test_init(void)
{
const struct cred *cred = current_cred();
struct key *key;
int ret;
register_key_type(&test_key_type);
key = key_alloc(&test_key_type, "test",
GLOBAL_ROOT_UID, GLOBAL_ROOT_GID, cred,
KEY_POS_SEARCH, KEY_ALLOC_NOT_IN_QUOTA, NULL);
if (IS_ERR(key))
return -1;
pr_info("keyring allocated successfully.\n");
ret = key_instantiate_and_link(key,
NULL,
sizeof(int),
current->cred->user->session_keyring,
NULL);
if (ret < 0) {
key_revoke(key);
key_put(key);
return ret;
}
return 0;
}
static void __exit test_exit(void)
{
unregister_key_type(&test_key_type);
}
module_init(test_init);
module_exit(test_exit);
MODULE_LICENSE("GPL");
next prev parent reply other threads:[~2019-02-26 9:09 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-01-25 7:16 [PATCH] security: keys: add NULL checking for key->type->instantiate Geliang Tang
2019-02-06 22:26 ` David Howells
2019-02-26 9:09 ` Geliang Tang [this message]
2019-02-26 9:11 ` Geliang Tang
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=20190226090903.GA3197@OptiPlex \
--to=geliangtang@gmail.com \
--cc=dhowells@redhat.com \
--cc=jmorris@namei.org \
--cc=keyrings@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-security-module@vger.kernel.org \
--cc=serge@hallyn.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;
as well as URLs for NNTP newsgroup(s).