Linux-Security-Module Archive on lore.kernel.org
 help / color / Atom feed
* [PATCH -next] KEYS: trusted: Switch to kmemdup_nul()
@ 2021-04-02  9:23 Yang Yingliang
  2021-04-04 16:01 ` Jarkko Sakkinen
  0 siblings, 1 reply; 3+ messages in thread
From: Yang Yingliang @ 2021-04-02  9:23 UTC (permalink / raw)
  To: linux-kernel, linux-security-module; +Cc: jejb, jarkko

Use kmemdup_nul() helper instead of open-coding to
simplify the code.

Reported-by: Hulk Robot <hulkci@huawei.com>
Signed-off-by: Yang Yingliang <yangyingliang@huawei.com>
---
 security/keys/trusted-keys/trusted_tpm1.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/security/keys/trusted-keys/trusted_tpm1.c b/security/keys/trusted-keys/trusted_tpm1.c
index 493eb91ed017..90ded4757e79 100644
--- a/security/keys/trusted-keys/trusted_tpm1.c
+++ b/security/keys/trusted-keys/trusted_tpm1.c
@@ -978,11 +978,9 @@ static int trusted_instantiate(struct key *key,
 	if (datalen <= 0 || datalen > 32767 || !prep->data)
 		return -EINVAL;
 
-	datablob = kmalloc(datalen + 1, GFP_KERNEL);
+	datablob = kmemdup_nul(prep->data, datalen, GFP_KERNEL);
 	if (!datablob)
 		return -ENOMEM;
-	memcpy(datablob, prep->data, datalen);
-	datablob[datalen] = '\0';
 
 	options = trusted_options_alloc();
 	if (!options) {
-- 
2.25.1


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH -next] KEYS: trusted: Switch to kmemdup_nul()
  2021-04-02  9:23 [PATCH -next] KEYS: trusted: Switch to kmemdup_nul() Yang Yingliang
@ 2021-04-04 16:01 ` Jarkko Sakkinen
  0 siblings, 0 replies; 3+ messages in thread
From: Jarkko Sakkinen @ 2021-04-04 16:01 UTC (permalink / raw)
  To: Yang Yingliang; +Cc: linux-kernel, linux-security-module, jejb

On Fri, Apr 02, 2021 at 05:23:46PM +0800, Yang Yingliang wrote:
> Use kmemdup_nul() helper instead of open-coding to
> simplify the code.
> 
> Reported-by: Hulk Robot <hulkci@huawei.com>
> Signed-off-by: Yang Yingliang <yangyingliang@huawei.com>
> ---
>  security/keys/trusted-keys/trusted_tpm1.c | 4 +---
>  1 file changed, 1 insertion(+), 3 deletions(-)


Acked-by: Jarkko Sakkinen <jarkko@kernel.org>

/Jarkko

> 
> diff --git a/security/keys/trusted-keys/trusted_tpm1.c b/security/keys/trusted-keys/trusted_tpm1.c
> index 493eb91ed017..90ded4757e79 100644
> --- a/security/keys/trusted-keys/trusted_tpm1.c
> +++ b/security/keys/trusted-keys/trusted_tpm1.c
> @@ -978,11 +978,9 @@ static int trusted_instantiate(struct key *key,
>  	if (datalen <= 0 || datalen > 32767 || !prep->data)
>  		return -EINVAL;
>  
> -	datablob = kmalloc(datalen + 1, GFP_KERNEL);
> +	datablob = kmemdup_nul(prep->data, datalen, GFP_KERNEL);
>  	if (!datablob)
>  		return -ENOMEM;
> -	memcpy(datablob, prep->data, datalen);
> -	datablob[datalen] = '\0';
>  
>  	options = trusted_options_alloc();
>  	if (!options) {
> -- 
> 2.25.1
> 
> 

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH -next] KEYS: trusted: Switch to kmemdup_nul()
@ 2021-04-12 16:00 Wei Yongjun
  0 siblings, 0 replies; 3+ messages in thread
From: Wei Yongjun @ 2021-04-12 16:00 UTC (permalink / raw)
  To: weiyongjun1, James Bottomley, Jarkko Sakkinen, Mimi Zohar,
	David Howells, James Morris, Serge E. Hallyn, Sumit Garg
  Cc: linux-integrity, keyrings, linux-security-module,
	kernel-janitors, Hulk Robot

Use kmemdup_nul() helper instead of open-coding to
simplify the code.

Reported-by: Hulk Robot <hulkci@huawei.com>
Signed-off-by: Wei Yongjun <weiyongjun1@huawei.com>
---
 security/keys/trusted-keys/trusted_core.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/security/keys/trusted-keys/trusted_core.c b/security/keys/trusted-keys/trusted_core.c
index ec3a066a4b42..9430cba1f084 100644
--- a/security/keys/trusted-keys/trusted_core.c
+++ b/security/keys/trusted-keys/trusted_core.c
@@ -146,11 +146,9 @@ static int trusted_instantiate(struct key *key,
 	if (datalen <= 0 || datalen > 32767 || !prep->data)
 		return -EINVAL;
 
-	datablob = kmalloc(datalen + 1, GFP_KERNEL);
+	datablob = kmemdup_nul(prep->data, datalen, GFP_KERNEL);
 	if (!datablob)
 		return -ENOMEM;
-	memcpy(datablob, prep->data, datalen);
-	datablob[datalen] = '\0';
 
 	payload = trusted_payload_alloc(key);
 	if (!payload) {


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, back to index

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-04-02  9:23 [PATCH -next] KEYS: trusted: Switch to kmemdup_nul() Yang Yingliang
2021-04-04 16:01 ` Jarkko Sakkinen
2021-04-12 16:00 Wei Yongjun

Linux-Security-Module Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-security-module/0 linux-security-module/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-security-module linux-security-module/ https://lore.kernel.org/linux-security-module \
		linux-security-module@vger.kernel.org
	public-inbox-index linux-security-module

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-security-module


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git