mirror of
				https://git.code.sf.net/p/linux-ima/ima-evm-utils
				synced 2025-10-26 02:41:07 +01:00 
			
		
		
		
	ima-evm-utils: Fix possible xattr_value overflows in calc_evm_hash
`selinux_str',`caps_str', and `ima_str' are passed from the command line but copied into the fixed-size buffer. Yes, length of `selinux_str' is calculated differently than of `caps_str'. Fixes: CID 229895. Signed-off-by: Vitaly Chikunov <vt@altlinux.org> Signed-off-by: Mimi Zohar <zohar@linux.ibm.com>
This commit is contained in:
		 Vitaly Chikunov
					Vitaly Chikunov
				
			
				
					committed by
					
						 Mimi Zohar
						Mimi Zohar
					
				
			
			
				
	
			
			
			 Mimi Zohar
						Mimi Zohar
					
				
			
						parent
						
							d47951c6e1
						
					
				
				
					commit
					4b7a74cc41
				
			
							
								
								
									
										21
									
								
								src/evmctl.c
									
									
									
									
									
								
							
							
						
						
									
										21
									
								
								src/evmctl.c
									
									
									
									
									
								
							| @@ -401,16 +401,31 @@ static int calc_evm_hash(const char *file, unsigned char *hash) | |||||||
|  |  | ||||||
| 	for (xattrname = evm_config_xattrnames; *xattrname != NULL; xattrname++) { | 	for (xattrname = evm_config_xattrnames; *xattrname != NULL; xattrname++) { | ||||||
| 		if (!strcmp(*xattrname, XATTR_NAME_SELINUX) && selinux_str) { | 		if (!strcmp(*xattrname, XATTR_NAME_SELINUX) && selinux_str) { | ||||||
| 			strcpy(xattr_value, selinux_str); |  | ||||||
| 			err = strlen(selinux_str) + 1; | 			err = strlen(selinux_str) + 1; | ||||||
|  | 			if (err > sizeof(xattr_value)) { | ||||||
|  | 				log_err("selinux[%u] value is too long to fit into xattr[%zu]\n", | ||||||
|  | 					err, sizeof(xattr_value)); | ||||||
|  | 				return -1; | ||||||
|  | 			} | ||||||
|  | 			strcpy(xattr_value, selinux_str); | ||||||
| 		} else if (!strcmp(*xattrname, XATTR_NAME_IMA) && ima_str) { | 		} else if (!strcmp(*xattrname, XATTR_NAME_IMA) && ima_str) { | ||||||
| 			hex2bin(xattr_value, ima_str, strlen(ima_str) / 2); |  | ||||||
| 			err = strlen(ima_str) / 2; | 			err = strlen(ima_str) / 2; | ||||||
|  | 			if (err > sizeof(xattr_value)) { | ||||||
|  | 				log_err("ima[%u] value is too long to fit into xattr[%zu]\n", | ||||||
|  | 					err, sizeof(xattr_value)); | ||||||
|  | 				return -1; | ||||||
|  | 			} | ||||||
|  | 			hex2bin(xattr_value, ima_str, err); | ||||||
| 		} else if (!strcmp(*xattrname, XATTR_NAME_CAPS) && (hmac_flags & HMAC_FLAG_CAPS_SET)) { | 		} else if (!strcmp(*xattrname, XATTR_NAME_CAPS) && (hmac_flags & HMAC_FLAG_CAPS_SET)) { | ||||||
| 			if (!caps_str) | 			if (!caps_str) | ||||||
| 				continue; | 				continue; | ||||||
| 			strcpy(xattr_value, caps_str); |  | ||||||
| 			err = strlen(caps_str); | 			err = strlen(caps_str); | ||||||
|  | 			if (err >= sizeof(xattr_value)) { | ||||||
|  | 				log_err("caps[%u] value is too long to fit into xattr[%zu]\n", | ||||||
|  | 					err + 1, sizeof(xattr_value)); | ||||||
|  | 				return -1; | ||||||
|  | 			} | ||||||
|  | 			strcpy(xattr_value, caps_str); | ||||||
| 		} else { | 		} else { | ||||||
| 			err = lgetxattr(file, *xattrname, xattr_value, sizeof(xattr_value)); | 			err = lgetxattr(file, *xattrname, xattr_value, sizeof(xattr_value)); | ||||||
| 			if (err < 0) { | 			if (err < 0) { | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user