linux-security-module.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] smackfs: check for allocation failure of kmalloc()
@ 2022-06-13  6:22 Li Qiong
  2022-06-13 14:53 ` Casey Schaufler
  0 siblings, 1 reply; 3+ messages in thread
From: Li Qiong @ 2022-06-13  6:22 UTC (permalink / raw)
  To: Casey Schaufler, James Morris, Serge E . Hallyn
  Cc: linux-security-module, linux-kernel, yuzhe, renyu, Li Qiong

As the possible failure of the kmalloc(), it should be better
to check it and print a warning message.

Signed-off-by: Li Qiong <liqiong@nfschina.com>
---
 security/smack/smackfs.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/security/smack/smackfs.c b/security/smack/smackfs.c
index 4b58526450d4..0d11ba3cb4cd 100644
--- a/security/smack/smackfs.c
+++ b/security/smack/smackfs.c
@@ -695,6 +695,11 @@ static void smk_cipso_doi(void)
 		       __func__, __LINE__, rc);
 
 	doip = kmalloc(sizeof(struct cipso_v4_doi), GFP_KERNEL | __GFP_NOFAIL);
+	if (unlikely(!doip)) {
+		printk(KERN_WARNING "%s:%d failed to allocate a memory for doip\n",
+		       __func__, __LINE__);
+		return;
+	}
 	doip->map.std = NULL;
 	doip->doi = smk_cipso_doi_value;
 	doip->type = CIPSO_V4_MAP_PASS;
-- 
2.25.1


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

* Re: [PATCH] smackfs: check for allocation failure of kmalloc()
  2022-06-13  6:22 [PATCH] smackfs: check for allocation failure of kmalloc() Li Qiong
@ 2022-06-13 14:53 ` Casey Schaufler
  2022-06-13 15:33   ` liqiong
  0 siblings, 1 reply; 3+ messages in thread
From: Casey Schaufler @ 2022-06-13 14:53 UTC (permalink / raw)
  To: Li Qiong, James Morris, Serge E . Hallyn
  Cc: linux-security-module, linux-kernel, yuzhe, renyu, Casey Schaufler

On 6/12/2022 11:22 PM, Li Qiong wrote:
> As the possible failure of the kmalloc(), it should be better
> to check it and print a warning message.

The allocation is done with __GFP_NOFAIL, which assures
it will not fail.

>
> Signed-off-by: Li Qiong <liqiong@nfschina.com>
> ---
>   security/smack/smackfs.c | 5 +++++
>   1 file changed, 5 insertions(+)
>
> diff --git a/security/smack/smackfs.c b/security/smack/smackfs.c
> index 4b58526450d4..0d11ba3cb4cd 100644
> --- a/security/smack/smackfs.c
> +++ b/security/smack/smackfs.c
> @@ -695,6 +695,11 @@ static void smk_cipso_doi(void)
>   		       __func__, __LINE__, rc);
>   
>   	doip = kmalloc(sizeof(struct cipso_v4_doi), GFP_KERNEL | __GFP_NOFAIL);
> +	if (unlikely(!doip)) {
> +		printk(KERN_WARNING "%s:%d failed to allocate a memory for doip\n",
> +		       __func__, __LINE__);
> +		return;
> +	}
>   	doip->map.std = NULL;
>   	doip->doi = smk_cipso_doi_value;
>   	doip->type = CIPSO_V4_MAP_PASS;

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

* Re: [PATCH] smackfs: check for allocation failure of kmalloc()
  2022-06-13 14:53 ` Casey Schaufler
@ 2022-06-13 15:33   ` liqiong
  0 siblings, 0 replies; 3+ messages in thread
From: liqiong @ 2022-06-13 15:33 UTC (permalink / raw)
  To: Casey Schaufler, James Morris, Serge E . Hallyn
  Cc: linux-security-module, linux-kernel, yuzhe, renyu



在 2022年06月13日 22:53, Casey Schaufler 写道:
> On 6/12/2022 11:22 PM, Li Qiong wrote:
>> As the possible failure of the kmalloc(), it should be better
>> to check it and print a warning message.
>
> The allocation is done with __GFP_NOFAIL, which assures
> it will not fail.

Thanks,  my mistake.
Drop this patch.



>
>>
>> Signed-off-by: Li Qiong <liqiong@nfschina.com>
>> ---
>>   security/smack/smackfs.c | 5 +++++
>>   1 file changed, 5 insertions(+)
>>
>> diff --git a/security/smack/smackfs.c b/security/smack/smackfs.c
>> index 4b58526450d4..0d11ba3cb4cd 100644
>> --- a/security/smack/smackfs.c
>> +++ b/security/smack/smackfs.c
>> @@ -695,6 +695,11 @@ static void smk_cipso_doi(void)
>>                  __func__, __LINE__, rc);
>>         doip = kmalloc(sizeof(struct cipso_v4_doi), GFP_KERNEL | __GFP_NOFAIL);
>> +    if (unlikely(!doip)) {
>> +        printk(KERN_WARNING "%s:%d failed to allocate a memory for doip\n",
>> +               __func__, __LINE__);
>> +        return;
>> +    }
>>       doip->map.std = NULL;
>>       doip->doi = smk_cipso_doi_value;
>>       doip->type = CIPSO_V4_MAP_PASS;

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

end of thread, other threads:[~2022-06-13 18:39 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-06-13  6:22 [PATCH] smackfs: check for allocation failure of kmalloc() Li Qiong
2022-06-13 14:53 ` Casey Schaufler
2022-06-13 15:33   ` liqiong

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).