linux-security-module.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH AUTOSEL 4.19 09/47] smackfs: Fix use-after-free in netlbl_catmap_walk()
       [not found] <20211108175031.1190422-1-sashal@kernel.org>
@ 2021-11-08 17:49 ` Sasha Levin
  2021-11-08 17:49 ` [PATCH AUTOSEL 4.19 10/47] NET: IPV4: fix error "do not initialise globals to 0" Sasha Levin
  2021-11-08 17:50 ` [PATCH AUTOSEL 4.19 37/47] smackfs: use __GFP_NOFAIL for smk_cipso_doi() Sasha Levin
  2 siblings, 0 replies; 5+ messages in thread
From: Sasha Levin @ 2021-11-08 17:49 UTC (permalink / raw)
  To: linux-kernel, stable
  Cc: Pawan Gupta, syzbot+3f91de0b813cc3d19a80, Casey Schaufler,
	Sasha Levin, jmorris, serge, linux-security-module

From: Pawan Gupta <pawan.kumar.gupta@linux.intel.com>

[ Upstream commit 0817534ff9ea809fac1322c5c8c574be8483ea57 ]

Syzkaller reported use-after-free bug as described in [1]. The bug is
triggered when smk_set_cipso() tries to free stale category bitmaps
while there are concurrent reader(s) using the same bitmaps.

Wait for RCU grace period to finish before freeing the category bitmaps
in smk_set_cipso(). This makes sure that there are no more readers using
the stale bitmaps and freeing them should be safe.

[1] https://lore.kernel.org/netdev/000000000000a814c505ca657a4e@google.com/

Reported-by: syzbot+3f91de0b813cc3d19a80@syzkaller.appspotmail.com
Signed-off-by: Pawan Gupta <pawan.kumar.gupta@linux.intel.com>
Signed-off-by: Casey Schaufler <casey@schaufler-ca.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
 security/smack/smackfs.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/security/smack/smackfs.c b/security/smack/smackfs.c
index 009e83ee2d002..25705a72d31bc 100644
--- a/security/smack/smackfs.c
+++ b/security/smack/smackfs.c
@@ -859,6 +859,7 @@ static int smk_open_cipso(struct inode *inode, struct file *file)
 static ssize_t smk_set_cipso(struct file *file, const char __user *buf,
 				size_t count, loff_t *ppos, int format)
 {
+	struct netlbl_lsm_catmap *old_cat;
 	struct smack_known *skp;
 	struct netlbl_lsm_secattr ncats;
 	char mapcatset[SMK_CIPSOLEN];
@@ -948,9 +949,11 @@ static ssize_t smk_set_cipso(struct file *file, const char __user *buf,
 
 	rc = smk_netlbl_mls(maplevel, mapcatset, &ncats, SMK_CIPSOLEN);
 	if (rc >= 0) {
-		netlbl_catmap_free(skp->smk_netlabel.attr.mls.cat);
+		old_cat = skp->smk_netlabel.attr.mls.cat;
 		skp->smk_netlabel.attr.mls.cat = ncats.attr.mls.cat;
 		skp->smk_netlabel.attr.mls.lvl = ncats.attr.mls.lvl;
+		synchronize_rcu();
+		netlbl_catmap_free(old_cat);
 		rc = count;
 	}
 
-- 
2.33.0


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

* [PATCH AUTOSEL 4.19 10/47] NET: IPV4: fix error "do not initialise globals to 0"
       [not found] <20211108175031.1190422-1-sashal@kernel.org>
  2021-11-08 17:49 ` [PATCH AUTOSEL 4.19 09/47] smackfs: Fix use-after-free in netlbl_catmap_walk() Sasha Levin
@ 2021-11-08 17:49 ` Sasha Levin
  2021-11-09  1:49   ` Joe Perches
  2021-11-08 17:50 ` [PATCH AUTOSEL 4.19 37/47] smackfs: use __GFP_NOFAIL for smk_cipso_doi() Sasha Levin
  2 siblings, 1 reply; 5+ messages in thread
From: Sasha Levin @ 2021-11-08 17:49 UTC (permalink / raw)
  To: linux-kernel, stable
  Cc: wangzhitong, David S . Miller, Sasha Levin, paul, yoshfuji,
	dsahern, kuba, netdev, linux-security-module

From: wangzhitong <wangzhitong@uniontech.com>

[ Upstream commit db9c8e2b1e246fc2dc20828932949437793146cc ]

this patch fixes below Errors reported by checkpatch
    ERROR: do not initialise globals to 0
    +int cipso_v4_rbm_optfmt = 0;

Signed-off-by: wangzhitong <wangzhitong@uniontech.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
 net/ipv4/cipso_ipv4.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/net/ipv4/cipso_ipv4.c b/net/ipv4/cipso_ipv4.c
index e8b8dd1cb1576..75908722de47a 100644
--- a/net/ipv4/cipso_ipv4.c
+++ b/net/ipv4/cipso_ipv4.c
@@ -87,7 +87,7 @@ struct cipso_v4_map_cache_entry {
 static struct cipso_v4_map_cache_bkt *cipso_v4_cache;
 
 /* Restricted bitmap (tag #1) flags */
-int cipso_v4_rbm_optfmt = 0;
+int cipso_v4_rbm_optfmt;
 int cipso_v4_rbm_strictvalid = 1;
 
 /*
-- 
2.33.0


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

* [PATCH AUTOSEL 4.19 37/47] smackfs: use __GFP_NOFAIL for smk_cipso_doi()
       [not found] <20211108175031.1190422-1-sashal@kernel.org>
  2021-11-08 17:49 ` [PATCH AUTOSEL 4.19 09/47] smackfs: Fix use-after-free in netlbl_catmap_walk() Sasha Levin
  2021-11-08 17:49 ` [PATCH AUTOSEL 4.19 10/47] NET: IPV4: fix error "do not initialise globals to 0" Sasha Levin
@ 2021-11-08 17:50 ` Sasha Levin
  2 siblings, 0 replies; 5+ messages in thread
From: Sasha Levin @ 2021-11-08 17:50 UTC (permalink / raw)
  To: linux-kernel, stable
  Cc: Tetsuo Handa, syzbot, Tetsuo Handa, Casey Schaufler, Sasha Levin,
	jmorris, serge, linux-security-module

From: Tetsuo Handa <penguin-kernel@i-love.sakura.ne.jp>

[ Upstream commit f91488ee15bd3cac467e2d6a361fc2d34d1052ae ]

syzbot is reporting kernel panic at smk_cipso_doi() due to memory
allocation fault injection [1]. The reason for need to use panic() was
not explained. But since no fix was proposed for 18 months, for now
let's use __GFP_NOFAIL for utilizing syzbot resource on other bugs.

Link: https://syzkaller.appspot.com/bug?extid=89731ccb6fec15ce1c22 [1]
Reported-by: syzbot <syzbot+89731ccb6fec15ce1c22@syzkaller.appspotmail.com>
Signed-off-by: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
Signed-off-by: Casey Schaufler <casey@schaufler-ca.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
 security/smack/smackfs.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/security/smack/smackfs.c b/security/smack/smackfs.c
index 25705a72d31bc..9fdf404a318f9 100644
--- a/security/smack/smackfs.c
+++ b/security/smack/smackfs.c
@@ -721,9 +721,7 @@ static void smk_cipso_doi(void)
 		printk(KERN_WARNING "%s:%d remove rc = %d\n",
 		       __func__, __LINE__, rc);
 
-	doip = kmalloc(sizeof(struct cipso_v4_doi), GFP_KERNEL);
-	if (doip == NULL)
-		panic("smack:  Failed to initialize cipso DOI.\n");
+	doip = kmalloc(sizeof(struct cipso_v4_doi), GFP_KERNEL | __GFP_NOFAIL);
 	doip->map.std = NULL;
 	doip->doi = smk_cipso_doi_value;
 	doip->type = CIPSO_V4_MAP_PASS;
-- 
2.33.0


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

* Re: [PATCH AUTOSEL 4.19 10/47] NET: IPV4: fix error "do not initialise globals to 0"
  2021-11-08 17:49 ` [PATCH AUTOSEL 4.19 10/47] NET: IPV4: fix error "do not initialise globals to 0" Sasha Levin
@ 2021-11-09  1:49   ` Joe Perches
  2021-11-14 14:13     ` Sasha Levin
  0 siblings, 1 reply; 5+ messages in thread
From: Joe Perches @ 2021-11-09  1:49 UTC (permalink / raw)
  To: Sasha Levin, linux-kernel, stable
  Cc: wangzhitong, David S . Miller, paul, yoshfuji, dsahern, kuba,
	netdev, linux-security-module

On Mon, 2021-11-08 at 12:49 -0500, Sasha Levin wrote:
> From: wangzhitong <wangzhitong@uniontech.com>
> 
> [ Upstream commit db9c8e2b1e246fc2dc20828932949437793146cc ]
> 
> this patch fixes below Errors reported by checkpatch
>     ERROR: do not initialise globals to 0
>     +int cipso_v4_rbm_optfmt = 0;
> 
> Signed-off-by: wangzhitong <wangzhitong@uniontech.com>
> Signed-off-by: David S. Miller <davem@davemloft.net>
> Signed-off-by: Sasha Levin <sashal@kernel.org>
> ---
>  net/ipv4/cipso_ipv4.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/net/ipv4/cipso_ipv4.c b/net/ipv4/cipso_ipv4.c
> index e8b8dd1cb1576..75908722de47a 100644
> --- a/net/ipv4/cipso_ipv4.c
> +++ b/net/ipv4/cipso_ipv4.c
> @@ -87,7 +87,7 @@ struct cipso_v4_map_cache_entry {
>  static struct cipso_v4_map_cache_bkt *cipso_v4_cache;
>  
>  /* Restricted bitmap (tag #1) flags */
> -int cipso_v4_rbm_optfmt = 0;
> +int cipso_v4_rbm_optfmt;

I think this is a silly thing to backport unless it's required
for some other patch.

>  int cipso_v4_rbm_strictvalid = 1;
>  
>  /*



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

* Re: [PATCH AUTOSEL 4.19 10/47] NET: IPV4: fix error "do not initialise globals to 0"
  2021-11-09  1:49   ` Joe Perches
@ 2021-11-14 14:13     ` Sasha Levin
  0 siblings, 0 replies; 5+ messages in thread
From: Sasha Levin @ 2021-11-14 14:13 UTC (permalink / raw)
  To: Joe Perches
  Cc: linux-kernel, stable, wangzhitong, David S . Miller, paul,
	yoshfuji, dsahern, kuba, netdev, linux-security-module

On Mon, Nov 08, 2021 at 05:49:04PM -0800, Joe Perches wrote:
>On Mon, 2021-11-08 at 12:49 -0500, Sasha Levin wrote:
>> From: wangzhitong <wangzhitong@uniontech.com>
>>
>> [ Upstream commit db9c8e2b1e246fc2dc20828932949437793146cc ]
>>
>> this patch fixes below Errors reported by checkpatch
>>     ERROR: do not initialise globals to 0
>>     +int cipso_v4_rbm_optfmt = 0;
>>
>> Signed-off-by: wangzhitong <wangzhitong@uniontech.com>
>> Signed-off-by: David S. Miller <davem@davemloft.net>
>> Signed-off-by: Sasha Levin <sashal@kernel.org>
>> ---
>>  net/ipv4/cipso_ipv4.c | 2 +-
>>  1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/net/ipv4/cipso_ipv4.c b/net/ipv4/cipso_ipv4.c
>> index e8b8dd1cb1576..75908722de47a 100644
>> --- a/net/ipv4/cipso_ipv4.c
>> +++ b/net/ipv4/cipso_ipv4.c
>> @@ -87,7 +87,7 @@ struct cipso_v4_map_cache_entry {
>>  static struct cipso_v4_map_cache_bkt *cipso_v4_cache;
>>
>>  /* Restricted bitmap (tag #1) flags */
>> -int cipso_v4_rbm_optfmt = 0;
>> +int cipso_v4_rbm_optfmt;
>
>I think this is a silly thing to backport unless it's required
>for some other patch.

You're right - it's silly. I'll drop it.

-- 
Thanks,
Sasha

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

end of thread, other threads:[~2021-11-14 14:14 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <20211108175031.1190422-1-sashal@kernel.org>
2021-11-08 17:49 ` [PATCH AUTOSEL 4.19 09/47] smackfs: Fix use-after-free in netlbl_catmap_walk() Sasha Levin
2021-11-08 17:49 ` [PATCH AUTOSEL 4.19 10/47] NET: IPV4: fix error "do not initialise globals to 0" Sasha Levin
2021-11-09  1:49   ` Joe Perches
2021-11-14 14:13     ` Sasha Levin
2021-11-08 17:50 ` [PATCH AUTOSEL 4.19 37/47] smackfs: use __GFP_NOFAIL for smk_cipso_doi() Sasha Levin

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