linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH -next] evm: call dump_security_xattr() in all cases to remove code duplication
@ 2023-01-29  0:46 Xiu Jianfeng
  2023-01-29 16:15 ` Mimi Zohar
  0 siblings, 1 reply; 7+ messages in thread
From: Xiu Jianfeng @ 2023-01-29  0:46 UTC (permalink / raw)
  To: zohar, dmitry.kasatkin, paul, jmorris, serge
  Cc: linux-integrity, linux-security-module, linux-kernel

Currently dump_security_xattr() is used to dump security xattr value
which is larger than 64 bytes, otherwise, pr_debug() is used. In order
to remove code duplication, refator dump_security_xattr() and call it in
all cases.

Signed-off-by: Xiu Jianfeng <xiujianfeng@huawei.com>
---
 security/integrity/evm/evm_crypto.c | 33 ++++++++++++++---------------
 1 file changed, 16 insertions(+), 17 deletions(-)

diff --git a/security/integrity/evm/evm_crypto.c b/security/integrity/evm/evm_crypto.c
index 52b811da6989..033804f5a5f2 100644
--- a/security/integrity/evm/evm_crypto.c
+++ b/security/integrity/evm/evm_crypto.c
@@ -183,8 +183,8 @@ static void hmac_add_misc(struct shash_desc *desc, struct inode *inode,
  * Dump large security xattr values as a continuous ascii hexademical string.
  * (pr_debug is limited to 64 bytes.)
  */
-static void dump_security_xattr(const char *prefix, const void *src,
-				size_t count)
+static void dump_security_xattr_l(const char *prefix, const void *src,
+				  size_t count)
 {
 #if defined(DEBUG) || defined(CONFIG_DYNAMIC_DEBUG)
 	char *asciihex, *p;
@@ -200,6 +200,16 @@ static void dump_security_xattr(const char *prefix, const void *src,
 #endif
 }
 
+static void dump_security_xattr(const char *name, const char *value,
+				size_t value_len)
+{
+	if (value_len < 64)
+		pr_debug("%s: (%zu) [%*phN]\n", name, value_len,
+			 (int)value_len, value);
+	else
+		dump_security_xattr_l(name, value, value_len);
+}
+
 /*
  * Calculate the HMAC value across the set of protected security xattrs.
  *
@@ -254,15 +264,9 @@ static int evm_calc_hmac_or_hash(struct dentry *dentry,
 			if (is_ima)
 				ima_present = true;
 
-			if (req_xattr_value_len < 64)
-				pr_debug("%s: (%zu) [%*phN]\n", req_xattr_name,
-					 req_xattr_value_len,
-					 (int)req_xattr_value_len,
-					 req_xattr_value);
-			else
-				dump_security_xattr(req_xattr_name,
-						    req_xattr_value,
-						    req_xattr_value_len);
+			dump_security_xattr(req_xattr_name,
+					    req_xattr_value,
+					    req_xattr_value_len);
 			continue;
 		}
 		size = vfs_getxattr_alloc(&nop_mnt_idmap, dentry, xattr->name,
@@ -286,12 +290,7 @@ static int evm_calc_hmac_or_hash(struct dentry *dentry,
 		if (is_ima)
 			ima_present = true;
 
-		if (xattr_size < 64)
-			pr_debug("%s: (%zu) [%*phN]", xattr->name, xattr_size,
-				 (int)xattr_size, xattr_value);
-		else
-			dump_security_xattr(xattr->name, xattr_value,
-					    xattr_size);
+		dump_security_xattr(xattr->name, xattr_value, xattr_size);
 	}
 	hmac_add_misc(desc, inode, type, data->digest);
 
-- 
2.17.1


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

* Re: [PATCH -next] evm: call dump_security_xattr() in all cases to remove code duplication
  2023-01-29  0:46 [PATCH -next] evm: call dump_security_xattr() in all cases to remove code duplication Xiu Jianfeng
@ 2023-01-29 16:15 ` Mimi Zohar
  2023-01-30  4:02   ` xiujianfeng
  0 siblings, 1 reply; 7+ messages in thread
From: Mimi Zohar @ 2023-01-29 16:15 UTC (permalink / raw)
  To: Xiu Jianfeng, dmitry.kasatkin, paul, jmorris, serge
  Cc: linux-integrity, linux-security-module, linux-kernel

> @@ -254,15 +264,9 @@ static int evm_calc_hmac_or_hash(struct dentry *dentry,
>  			if (is_ima)
>  				ima_present = true;
>  
> -			if (req_xattr_value_len < 64)
> -				pr_debug("%s: (%zu) [%*phN]\n", req_xattr_name,
> -					 req_xattr_value_len,
> -					 (int)req_xattr_value_len,
> -					 req_xattr_value);
> -			else
> -				dump_security_xattr(req_xattr_name,
> -						    req_xattr_value,
> -						    req_xattr_value_len);
> +			dump_security_xattr(req_xattr_name,
> +					    req_xattr_value,
> +					    req_xattr_value_len);
>  			continue;
>  		}
>  		size = vfs_getxattr_alloc(&nop_mnt_idmap, dentry, xattr->name,

Hm, this patch doesn't apply properly.

Mimi



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

* Re: [PATCH -next] evm: call dump_security_xattr() in all cases to remove code duplication
  2023-01-29 16:15 ` Mimi Zohar
@ 2023-01-30  4:02   ` xiujianfeng
  2023-01-30 12:17     ` Mimi Zohar
  0 siblings, 1 reply; 7+ messages in thread
From: xiujianfeng @ 2023-01-30  4:02 UTC (permalink / raw)
  To: Mimi Zohar, dmitry.kasatkin, paul, jmorris, serge
  Cc: linux-integrity, linux-security-module, linux-kernel

Hi,

On 2023/1/30 0:15, Mimi Zohar wrote:
>> @@ -254,15 +264,9 @@ static int evm_calc_hmac_or_hash(struct dentry *dentry,
>>  			if (is_ima)
>>  				ima_present = true;
>>  
>> -			if (req_xattr_value_len < 64)
>> -				pr_debug("%s: (%zu) [%*phN]\n", req_xattr_name,
>> -					 req_xattr_value_len,
>> -					 (int)req_xattr_value_len,
>> -					 req_xattr_value);
>> -			else
>> -				dump_security_xattr(req_xattr_name,
>> -						    req_xattr_value,
>> -						    req_xattr_value_len);
>> +			dump_security_xattr(req_xattr_name,
>> +					    req_xattr_value,
>> +					    req_xattr_value_len);
>>  			continue;
>>  		}
>>  		size = vfs_getxattr_alloc(&nop_mnt_idmap, dentry, xattr->name,
> 
> Hm, this patch doesn't apply properly.

I noticed that the patch fails to apply on linux master, however this
patch is meant for linux-next, would you please maybe have a look?

> 
> Mimi>
> 

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

* Re: [PATCH -next] evm: call dump_security_xattr() in all cases to remove code duplication
  2023-01-30  4:02   ` xiujianfeng
@ 2023-01-30 12:17     ` Mimi Zohar
  2023-01-31  2:05       ` xiujianfeng
  0 siblings, 1 reply; 7+ messages in thread
From: Mimi Zohar @ 2023-01-30 12:17 UTC (permalink / raw)
  To: xiujianfeng, dmitry.kasatkin, paul, jmorris, serge, Christian Brauner b
  Cc: linux-integrity, linux-security-module, linux-kernel

[Cc: Christian Brauner <brauner@kernel.org>]

On Mon, 2023-01-30 at 12:02 +0800, xiujianfeng wrote:
> Hi,
> 
> On 2023/1/30 0:15, Mimi Zohar wrote:
> >> @@ -254,15 +264,9 @@ static int evm_calc_hmac_or_hash(struct dentry *dentry,
> >>  			if (is_ima)
> >>  				ima_present = true;
> >>  
> >> -			if (req_xattr_value_len < 64)
> >> -				pr_debug("%s: (%zu) [%*phN]\n", req_xattr_name,
> >> -					 req_xattr_value_len,
> >> -					 (int)req_xattr_value_len,
> >> -					 req_xattr_value);
> >> -			else
> >> -				dump_security_xattr(req_xattr_name,
> >> -						    req_xattr_value,
> >> -						    req_xattr_value_len);
> >> +			dump_security_xattr(req_xattr_name,
> >> +					    req_xattr_value,
> >> +					    req_xattr_value_len);
> >>  			continue;
> >>  		}
> >>  		size = vfs_getxattr_alloc(&nop_mnt_idmap, dentry, xattr->name,
> > 
> > Hm, this patch doesn't apply properly.
> 
> I noticed that the patch fails to apply on linux master, however this
> patch is meant for linux-next, would you please maybe have a look?

I wasn't aware of the change.  However, merge conflicts should not be
"fixed", but mentioned immediately after the patch break line ("---") .
FYI, this merge conflict is a result of commit 4609e1f18e19 ("fs: port
->permission() to pass mnt_idmap").

Patches for the linux-integrity branch should be based on the next-
integrity branch.
-- 
thanks,

Mimi


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

* Re: [PATCH -next] evm: call dump_security_xattr() in all cases to remove code duplication
  2023-01-30 12:17     ` Mimi Zohar
@ 2023-01-31  2:05       ` xiujianfeng
  0 siblings, 0 replies; 7+ messages in thread
From: xiujianfeng @ 2023-01-31  2:05 UTC (permalink / raw)
  To: Mimi Zohar, dmitry.kasatkin, paul, jmorris, serge, Christian Brauner b
  Cc: linux-integrity, linux-security-module, linux-kernel



On 2023/1/30 20:17, Mimi Zohar wrote:
> [Cc: Christian Brauner <brauner@kernel.org>]
> 
> On Mon, 2023-01-30 at 12:02 +0800, xiujianfeng wrote:
>> Hi,
>>
>> On 2023/1/30 0:15, Mimi Zohar wrote:
>>>> @@ -254,15 +264,9 @@ static int evm_calc_hmac_or_hash(struct dentry *dentry,
>>>>  			if (is_ima)
>>>>  				ima_present = true;
>>>>  
>>>> -			if (req_xattr_value_len < 64)
>>>> -				pr_debug("%s: (%zu) [%*phN]\n", req_xattr_name,
>>>> -					 req_xattr_value_len,
>>>> -					 (int)req_xattr_value_len,
>>>> -					 req_xattr_value);
>>>> -			else
>>>> -				dump_security_xattr(req_xattr_name,
>>>> -						    req_xattr_value,
>>>> -						    req_xattr_value_len);
>>>> +			dump_security_xattr(req_xattr_name,
>>>> +					    req_xattr_value,
>>>> +					    req_xattr_value_len);
>>>>  			continue;
>>>>  		}
>>>>  		size = vfs_getxattr_alloc(&nop_mnt_idmap, dentry, xattr->name,
>>>
>>> Hm, this patch doesn't apply properly.
>>
>> I noticed that the patch fails to apply on linux master, however this
>> patch is meant for linux-next, would you please maybe have a look?
> 
> I wasn't aware of the change.  However, merge conflicts should not be
> "fixed", but mentioned immediately after the patch break line ("---") .
> FYI, this merge conflict is a result of commit 4609e1f18e19 ("fs: port
> ->permission() to pass mnt_idmap").
> 
> Patches for the linux-integrity branch should be based on the next-
> integrity branch.

Thanks mimi, I assume you mean next-integrity branch on
https://git.kernel.org/pub/scm/linux/kernel/git/zohar/linux-integrity.git/,
new patch already sent.

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

* Re: [PATCH -next] evm: call dump_security_xattr() in all cases to remove code duplication
  2023-01-31  2:00 Xiu Jianfeng
@ 2023-01-31  2:11 ` xiujianfeng
  0 siblings, 0 replies; 7+ messages in thread
From: xiujianfeng @ 2023-01-31  2:11 UTC (permalink / raw)
  To: zohar, dmitry.kasatkin, paul, jmorris, serge
  Cc: linux-integrity, linux-security-module, linux-kernel

sorry, I forget to add v2 tag, this is based on commit b8dc57947379
("ima: fix ima_delete_rules() kernel-doc warning").

On 2023/1/31 10:00, Xiu Jianfeng wrote:
> Currently dump_security_xattr() is used to dump security xattr value
> which is larger than 64 bytes, otherwise, pr_debug() is used. In order
> to remove code duplication, refator dump_security_xattr() and call it in
> all cases.
> 
> Signed-off-by: Xiu Jianfeng <xiujianfeng@huawei.com>
> ---
>  security/integrity/evm/evm_crypto.c | 33 ++++++++++++++---------------
>  1 file changed, 16 insertions(+), 17 deletions(-)
> 
> diff --git a/security/integrity/evm/evm_crypto.c b/security/integrity/evm/evm_crypto.c
> index fa5ff13fa8c9..0fe6c9cd8eab 100644
> --- a/security/integrity/evm/evm_crypto.c
> +++ b/security/integrity/evm/evm_crypto.c
> @@ -183,8 +183,8 @@ static void hmac_add_misc(struct shash_desc *desc, struct inode *inode,
>   * Dump large security xattr values as a continuous ascii hexademical string.
>   * (pr_debug is limited to 64 bytes.)
>   */
> -static void dump_security_xattr(const char *prefix, const void *src,
> -				size_t count)
> +static void dump_security_xattr_l(const char *prefix, const void *src,
> +				  size_t count)
>  {
>  #if defined(DEBUG) || defined(CONFIG_DYNAMIC_DEBUG)
>  	char *asciihex, *p;
> @@ -200,6 +200,16 @@ static void dump_security_xattr(const char *prefix, const void *src,
>  #endif
>  }
>  
> +static void dump_security_xattr(const char *name, const char *value,
> +				size_t value_len)
> +{
> +	if (value_len < 64)
> +		pr_debug("%s: (%zu) [%*phN]\n", name, value_len,
> +			 (int)value_len, value);
> +	else
> +		dump_security_xattr_l(name, value, value_len);
> +}
> +
>  /*
>   * Calculate the HMAC value across the set of protected security xattrs.
>   *
> @@ -254,15 +264,9 @@ static int evm_calc_hmac_or_hash(struct dentry *dentry,
>  			if (is_ima)
>  				ima_present = true;
>  
> -			if (req_xattr_value_len < 64)
> -				pr_debug("%s: (%zu) [%*phN]\n", req_xattr_name,
> -					 req_xattr_value_len,
> -					 (int)req_xattr_value_len,
> -					 req_xattr_value);
> -			else
> -				dump_security_xattr(req_xattr_name,
> -						    req_xattr_value,
> -						    req_xattr_value_len);
> +			dump_security_xattr(req_xattr_name,
> +					    req_xattr_value,
> +					    req_xattr_value_len);
>  			continue;
>  		}
>  		size = vfs_getxattr_alloc(&init_user_ns, dentry, xattr->name,
> @@ -286,12 +290,7 @@ static int evm_calc_hmac_or_hash(struct dentry *dentry,
>  		if (is_ima)
>  			ima_present = true;
>  
> -		if (xattr_size < 64)
> -			pr_debug("%s: (%zu) [%*phN]", xattr->name, xattr_size,
> -				 (int)xattr_size, xattr_value);
> -		else
> -			dump_security_xattr(xattr->name, xattr_value,
> -					    xattr_size);
> +		dump_security_xattr(xattr->name, xattr_value, xattr_size);
>  	}
>  	hmac_add_misc(desc, inode, type, data->digest);
>  

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

* [PATCH -next] evm: call dump_security_xattr() in all cases to remove code duplication
@ 2023-01-31  2:00 Xiu Jianfeng
  2023-01-31  2:11 ` xiujianfeng
  0 siblings, 1 reply; 7+ messages in thread
From: Xiu Jianfeng @ 2023-01-31  2:00 UTC (permalink / raw)
  To: zohar, dmitry.kasatkin, paul, jmorris, serge
  Cc: linux-integrity, linux-security-module, linux-kernel

Currently dump_security_xattr() is used to dump security xattr value
which is larger than 64 bytes, otherwise, pr_debug() is used. In order
to remove code duplication, refator dump_security_xattr() and call it in
all cases.

Signed-off-by: Xiu Jianfeng <xiujianfeng@huawei.com>
---
 security/integrity/evm/evm_crypto.c | 33 ++++++++++++++---------------
 1 file changed, 16 insertions(+), 17 deletions(-)

diff --git a/security/integrity/evm/evm_crypto.c b/security/integrity/evm/evm_crypto.c
index fa5ff13fa8c9..0fe6c9cd8eab 100644
--- a/security/integrity/evm/evm_crypto.c
+++ b/security/integrity/evm/evm_crypto.c
@@ -183,8 +183,8 @@ static void hmac_add_misc(struct shash_desc *desc, struct inode *inode,
  * Dump large security xattr values as a continuous ascii hexademical string.
  * (pr_debug is limited to 64 bytes.)
  */
-static void dump_security_xattr(const char *prefix, const void *src,
-				size_t count)
+static void dump_security_xattr_l(const char *prefix, const void *src,
+				  size_t count)
 {
 #if defined(DEBUG) || defined(CONFIG_DYNAMIC_DEBUG)
 	char *asciihex, *p;
@@ -200,6 +200,16 @@ static void dump_security_xattr(const char *prefix, const void *src,
 #endif
 }
 
+static void dump_security_xattr(const char *name, const char *value,
+				size_t value_len)
+{
+	if (value_len < 64)
+		pr_debug("%s: (%zu) [%*phN]\n", name, value_len,
+			 (int)value_len, value);
+	else
+		dump_security_xattr_l(name, value, value_len);
+}
+
 /*
  * Calculate the HMAC value across the set of protected security xattrs.
  *
@@ -254,15 +264,9 @@ static int evm_calc_hmac_or_hash(struct dentry *dentry,
 			if (is_ima)
 				ima_present = true;
 
-			if (req_xattr_value_len < 64)
-				pr_debug("%s: (%zu) [%*phN]\n", req_xattr_name,
-					 req_xattr_value_len,
-					 (int)req_xattr_value_len,
-					 req_xattr_value);
-			else
-				dump_security_xattr(req_xattr_name,
-						    req_xattr_value,
-						    req_xattr_value_len);
+			dump_security_xattr(req_xattr_name,
+					    req_xattr_value,
+					    req_xattr_value_len);
 			continue;
 		}
 		size = vfs_getxattr_alloc(&init_user_ns, dentry, xattr->name,
@@ -286,12 +290,7 @@ static int evm_calc_hmac_or_hash(struct dentry *dentry,
 		if (is_ima)
 			ima_present = true;
 
-		if (xattr_size < 64)
-			pr_debug("%s: (%zu) [%*phN]", xattr->name, xattr_size,
-				 (int)xattr_size, xattr_value);
-		else
-			dump_security_xattr(xattr->name, xattr_value,
-					    xattr_size);
+		dump_security_xattr(xattr->name, xattr_value, xattr_size);
 	}
 	hmac_add_misc(desc, inode, type, data->digest);
 
-- 
2.17.1


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

end of thread, other threads:[~2023-01-31  2:11 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-01-29  0:46 [PATCH -next] evm: call dump_security_xattr() in all cases to remove code duplication Xiu Jianfeng
2023-01-29 16:15 ` Mimi Zohar
2023-01-30  4:02   ` xiujianfeng
2023-01-30 12:17     ` Mimi Zohar
2023-01-31  2:05       ` xiujianfeng
2023-01-31  2:00 Xiu Jianfeng
2023-01-31  2:11 ` xiujianfeng

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