Skip to contentSkip to conversation

security/keys: replace BUG() in unreachable default cases

PATCH In review Mohammed EL Kadiri 2 participants 5 messages Jun 13 – Jun 15

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

cover security/keys: replace BUG() in unreachable default cases

Replace BUG() in two switch default cases with proper error returns.

Mohammed EL Kadiri (2):
keys: request_key: replace BUG with return -EINVAL
keys: keyctl_pkey: replace BUG with return -EOPNOTSUPP

 security/keys/keyctl_pkey.c | 5 +++--
 security/keys/request_key.c | 2 +-
 2 files changed, 4 insertions(+), 3 deletions(-)
Signature · 1 line
2.43.0
#1 lore raw

PATCH 1/2 keys: request_key: replace BUG with return -EINVAL

Replace BUG() in construct_get_dest_keyring() default case with return -EINVAL to handle the unimplemented group keyring destination gracefully.

---
 security/keys/request_key.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
security/keys/request_key.c +1 -1
index a7673ad86d18..fa2bb9f2f538 100644
@@ -332,7 +332,7 @@ static int construct_get_dest_keyring(struct key **_dest_keyring)
 
 		case KEY_REQKEY_DEFL_GROUP_KEYRING:
 		default:
-			BUG();
+			return -EINVAL;
 		}
 
 		/*
Signature · 1 line
2.43.0
maintainer Reviewed-by on v1 1/2
#2 lore raw

Re: [PATCH 1/2] keys: request_key: replace BUG with return -EINVAL

Quoted 25 lines · Mohammed EL Kadiri

Replace BUG() in construct_get_dest_keyring() default case with return -EINVAL to handle the unimplemented group keyring destination gracefully.

---
 security/keys/request_key.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
security/keys/request_key.c +1 -1
index a7673ad86d18..fa2bb9f2f538 100644
@@ -332,7 +332,7 @@ static int construct_get_dest_keyring(struct key **_dest_keyring)
 
 		case KEY_REQKEY_DEFL_GROUP_KEYRING:
 		default:
-			BUG();
+			return -EINVAL;
 		}
 
 		/*
Signature · 1 line
2.43.0

BR, Jarkko

#3 lore raw

PATCH 2/2 keys: keyctl_pkey: replace BUG with return -EOPNOTSUPP

In reply to Mohammed EL Kadiri

Replace two BUG() calls in keyctl_pkey_params_get_2() and keyctl_pkey_e_d_s() default cases with -EOPNOTSUPP, matching the error style already used in these functions.

---
 security/keys/keyctl_pkey.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
security/keys/keyctl_pkey.c +3 -2
index 97bc27bbf079..6b2821ffeb6c 100644
@@ -155,7 +155,7 @@ static int keyctl_pkey_params_get_2(const struct keyctl_pkey_params __user *_par
 			return -EINVAL;
 		break;
 	default:
-		BUG();
+		return -EOPNOTSUPP;
 	}
 
 	params->in_len  = uparams.in_len;
@@ -238,7 +238,8 @@ long keyctl_pkey_e_d_s(int op,
 		params.op = kernel_pkey_sign;
 		break;
 	default:
-		BUG();
+		ret = -EOPNOTSUPP;
+		goto error_params;
 	}
 
 	in = memdup_user(_in, params.in_len);
Signature · 1 line
2.43.0
maintainer Reviewed-by on v1 2/2
#4 lore raw

Re: [PATCH 2/2] keys: keyctl_pkey: replace BUG with return -EOPNOTSUPP

Quoted 35 lines · Mohammed EL Kadiri

Replace two BUG() calls in keyctl_pkey_params_get_2() and keyctl_pkey_e_d_s() default cases with -EOPNOTSUPP, matching the error style already used in these functions.

---
 security/keys/keyctl_pkey.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
security/keys/keyctl_pkey.c +3 -2
index 97bc27bbf079..6b2821ffeb6c 100644
@@ -155,7 +155,7 @@ static int keyctl_pkey_params_get_2(const struct keyctl_pkey_params __user *_par
 			return -EINVAL;
 		break;
 	default:
-		BUG();
+		return -EOPNOTSUPP;
 	}
 
 	params->in_len  = uparams.in_len;
@@ -238,7 +238,8 @@ long keyctl_pkey_e_d_s(int op,
 		params.op = kernel_pkey_sign;
 		break;
 	default:
-		BUG();
+		ret = -EOPNOTSUPP;
+		goto error_params;
 	}
 
 	in = memdup_user(_in, params.in_len);
Signature · 1 line
2.43.0

Thank you.

BR, Jarkko