s390/pkey: Use memdup_user() rather than duplicating its implementation
Subsystems (3)
PATCH 1/1 s390/pkey: Use memdup_user() rather than duplicating its implementation
From: Markus Elfring <[email protected]>
Date: Wed, 6 Nov 2019 11:11:42 +0100
Reuse existing functionality from memdup_user() instead of keeping duplicate source code.
Generated by: scripts/coccinelle/api/memdup_user.cocci
Delete local variables which became unnecessary with this refactoring in two function implementations.
--- drivers/s390/crypto/pkey_api.c | 32 ++++++-------------------------- 1 file changed, 6 insertions(+), 26 deletions(-)
drivers/s390/crypto/pkey_api.c +6 -26
@@ -715,36 +715,16 @@ static int pkey_apqns4keytype(enum pkey_key_type ktype,static void *_copy_key_from_user (void __user *ukey,size_t keylen) { -void *kkey; - -if (!ukey || keylen <MINKEYBLOBSIZE || keylen >KEYBLOBBUFSIZE ) -return ERR_PTR (-EINVAL ); - kkey =kmalloc (keylen,GFP_KERNEL ); -if (!kkey) -return ERR_PTR (-ENOMEM ); -if (copy_from_user (kkey, ukey, keylen)) { -kfree (kkey); -return ERR_PTR (-EFAULT ); - } - -return kkey; +return !ukey || keylen <MINKEYBLOBSIZE || keylen >KEYBLOBBUFSIZE + ?ERR_PTR (-EINVAL ) + :memdup_user (ukey, keylen); }static void *_copy_apqns_from_user (void __user *uapqns,size_t nr_apqns) { -void *kapqns =NULL ; -size_t nbytes; - -if (uapqns && nr_apqns >0 ) { - nbytes = nr_apqns *sizeof (struct pkey_apqn ); - kapqns =kmalloc (nbytes,GFP_KERNEL ); -if (!kapqns) -return ERR_PTR (-ENOMEM ); -if (copy_from_user (kapqns, uapqns, nbytes)) -return ERR_PTR (-EFAULT ); - } - -return kapqns; +return uapqns && nr_apqns >0 + ?memdup_user (uapqns, nr_apqns *sizeof (struct pkey_apqn )) + :NULL ; } static long pkey_unlocked_ioctl(struct file *filp, unsigned int cmd,
--
2.24.0
Quoted 6 lines · Markus Elfring
From: Markus Elfring <[email protected]>
Date: Wed, 6 Nov 2019 11:11:42 +0100Reuse existing functionality from
memdup_user()instead of keeping duplicate source code.
Quoted 6 lines
Generated by:
scripts/coccinelle/api/memdup_user.cocciDelete local variables which became unnecessary with this refactoring in two function implementations.
Fixes f2bbc96e7cfad3891b7bf9bd3e566b9b7ab4553d ("s390/pkey: add CCA AES cipher key support")
This doesn't fix anything and the Fixes: line is not appropriate.
drivers/s390/crypto/pkey_api.c
Quoted 1 line
drivers/s390/crypto/pkey_api.c +0
-0
[]
Quoted 10 lines
drivers/s390/crypto/pkey_api.c +0
-6@@ -715,36 +715,16 @@ static int pkey_apqns4keytype(enum pkey_key_type ktype,static void *_copy_key_from_user (void __user *ukey,size_t keylen) { -void *kkey; - -if (!ukey || keylen <MINKEYBLOBSIZE || keylen >KEYBLOBBUFSIZE ) -return ERR_PTR (-EINVAL ); - kkey =kmalloc (keylen,GFP_KERNEL ); -if (!kkey)
drivers/s390/crypto/pkey_api.c static int pkey_apqns4keytype(enum pkey_key_type ktype, · line 720
Quoted 10 lines
drivers/s390/crypto/pkey_api.c +3
-7-return ERR_PTR (-ENOMEM ); -if (copy_from_user (kkey, ukey, keylen)) { -kfree (kkey); -return ERR_PTR (-EFAULT ); - } - -return kkey; +return !ukey || keylen <MINKEYBLOBSIZE || keylen >KEYBLOBBUFSIZE + ?ERR_PTR (-EINVAL ) + :memdup_user (ukey, keylen);
This is a very poor use of ternary ?: code.
This is much more readable for humans.
if (!ukey || keylen < MINKEYBLOBSIZE || keylen > KBLOBBUFSIZE) return ERR_PTR(-EINVAL); return memdup_user(ukey, keylen);
The compiler will produce the same code.
Quoted 8 lines
drivers/s390/crypto/pkey_api.c +0
-6static void *_copy_apqns_from_user (void __user *uapqns,size_t nr_apqns) { -void *kapqns =NULL ; -size_t nbytes; - -if (uapqns && nr_apqns >0 ) { - nbytes = nr_apqns *sizeof (struct pkey_apqn ); - kapqns =kmalloc (nbytes,GFP_KERNEL );
drivers/s390/crypto/pkey_api.c static int pkey_apqns4keytype(enum pkey_key_type ktype, · line 727
Quoted 10 lines
drivers/s390/crypto/pkey_api.c +3
-7-if (!kapqns) -return ERR_PTR (-ENOMEM ); -if (copy_from_user (kapqns, uapqns, nbytes)) -return ERR_PTR (-EFAULT ); - } - -return kapqns; +return uapqns && nr_apqns >0 + ?memdup_user (uapqns, nr_apqns *sizeof (struct pkey_apqn )) + :NULL ;
And here you reverse the form of the earlier block. Please be consistent and use this style:
if (!uapqns || nr_apqns <= 0) return NULL; return memdup_user(uapqns, nr_apqns * sizeof(struct pkey_apqn));
Quoted 4 lines
Quoted 4 lines
Reuse existing functionality from
memdup_user()instead of keeping duplicate source code.Generated by:
scripts/coccinelle/api/memdup_user.cocci
…
Quoted 3 lines
Quoted 1 line
Fixes f2bbc96e7cfad3891b7bf9bd3e566b9b7ab4553d ("s390/pkey: add CCA AES cipher key support")This doesn't fix anything
How would you categorise the proposed source code reduction and software reuse?
Quoted 1 line
and the Fixes: line is not appropriate.
Will the development opinions vary between contributors?
Quoted 5 lines
drivers/s390/crypto/pkey_api.c static int pkey_apqns4keytype(enum pkey_key_type ktype, · line 720
Quoted 3 lines
drivers/s390/crypto/pkey_api.c +3
-0+return !ukey || keylen <MINKEYBLOBSIZE || keylen >KEYBLOBBUFSIZE + ?ERR_PTR (-EINVAL ) + :memdup_user (ukey, keylen);This is a very poor use of ternary ?: code.
The conditional operator is applied once more in the intended way, isn't it?
Quoted 1 line
This is much more readable for humans.
Readability preferences can vary also for this code structure.
Quoted 5 lines
drivers/s390/crypto/pkey_api.c static int pkey_apqns4keytype(enum pkey_key_type ktype, · line 727
Quoted 3 lines
drivers/s390/crypto/pkey_api.c +3
-0+return uapqns && nr_apqns >0 + ?memdup_user (uapqns, nr_apqns *sizeof (struct pkey_apqn )) + :NULL ;And here you reverse the form of the earlier block.
I kept the previous condition specification.
Quoted 1 line
Please be consistent and use this style:
Would further developers like to get a more verbose variant for this software transformation?
Regards,
Markus
Quoted 10 lines · Markus Elfring
Quoted 4 lines
Quoted 4 lines
Reuse existing functionality from
memdup_user()instead of keeping duplicate source code.Generated by:
scripts/coccinelle/api/memdup_user.cocci…
Quoted 3 lines
Quoted 1 line
Fixes f2bbc96e7cfad3891b7bf9bd3e566b9b7ab4553d ("s390/pkey: add CCA AES cipher key support")This doesn't fix anything
How would you categorise the proposed source code reduction and software reuse?
As inappropriate for a fixes tag.
The fixes tag is "used to make it easy to determine where a bug originated, which can help review a bug fix"
There is no bug here.
Quoted 1 line
Will the development opinions vary between contributors?
Ever had a bikeshed?
Quoted 8 lines
Quoted 5 lines
drivers/s390/crypto/pkey_api.c static int pkey_apqns4keytype(enum pkey_key_type ktype, · line 720
Quoted 3 lines
drivers/s390/crypto/pkey_api.c +3
-0+return !ukey || keylen <MINKEYBLOBSIZE || keylen >KEYBLOBBUFSIZE + ?ERR_PTR (-EINVAL ) + :memdup_user (ukey, keylen);This is a very poor use of ternary ?: code.
The conditional operator is applied once more in the intended way, isn't it?
Please take your development efforts to obfuscated c contests.
Quoted 1 line
There is no bug here.
Do you find duplicated source code questionable?
Is this also an error item?
Regards,
Markus
Quoted 3 lines · Markus Elfring
Quoted 1 line
There is no bug here.
Do you find duplicated source code questionable?
No. It is something that can be improved through
code consolidation though.
Quoted 1 line
Is this also an error item?
Definitely not. It is _only_ an error if there is some logic defect. There is no logic defect here.
Quoted 5 lines
Quoted 3 lines
Quoted 1 line
There is no bug here.
Do you find duplicated source code questionable?
No.
Do you disagree to the following information which can be provided by a coccicheck run?
./drivers/s390/crypto/pkey_api.c:722:8-15: WARNING opportunity for memdup_user
Quoted 6 lines
It is something that can be improved through
code consolidation though.Quoted 1 line
Is this also an error item?
Definitely not.
Your view seems to be very limited at the moment.
Quoted 2 lines
It is _only_ an error if there is some logic defect. There is no logic defect here.
I suggest to consider additional software weaknesses besides logic errors. Do we occasionally care any more for the development principle “Don't repeat yourself”?
Regards,
Markus
Quoted 4 lines
Quoted 4 lines
Reuse existing functionality from
memdup_user()instead of keeping duplicate source code.Generated by:
scripts/coccinelle/api/memdup_user.cocci
…
Quoted 3 lines
Quoted 1 line
Fixes f2bbc96e7cfad3891b7bf9bd3e566b9b7ab4553d ("s390/pkey: add CCA AES cipher key support")This doesn't fix anything
How would you categorise the proposed source code reduction and software reuse?
Quoted 1 line
and the Fixes: line is not appropriate.
Will the development opinions vary between contributors?
Quoted 5 lines
drivers/s390/crypto/pkey_api.c static int pkey_apqns4keytype(enum pkey_key_type ktype, · line 720
Quoted 3 lines
drivers/s390/crypto/pkey_api.c +3
-0+return !ukey || keylen <MINKEYBLOBSIZE || keylen >KEYBLOBBUFSIZE + ?ERR_PTR (-EINVAL ) + :memdup_user (ukey, keylen);This is a very poor use of ternary ?: code.
The conditional operator is applied once more in the intended way, isn't it?
Quoted 1 line
This is much more readable for humans.
Readability preferences can vary also for this code structure.
Quoted 5 lines
drivers/s390/crypto/pkey_api.c static int pkey_apqns4keytype(enum pkey_key_type ktype, · line 727
Quoted 3 lines
drivers/s390/crypto/pkey_api.c +3
-0+return uapqns && nr_apqns >0 + ?memdup_user (uapqns, nr_apqns *sizeof (struct pkey_apqn )) + :NULL ;And here you reverse the form of the earlier block.
I kept the previous condition specification.
Quoted 1 line
Please be consistent and use this style:
Would further developers like to get a more verbose variant for this software transformation?
Regards,
Markus
Quoted 10 lines · Markus Elfring
Quoted 4 lines
Quoted 4 lines
Reuse existing functionality from
memdup_user()instead of keeping duplicate source code.Generated by:
scripts/coccinelle/api/memdup_user.cocci…
Quoted 3 lines
Quoted 1 line
Fixes f2bbc96e7cfad3891b7bf9bd3e566b9b7ab4553d ("s390/pkey: add CCA AES cipher key support")This doesn't fix anything
How would you categorise the proposed source code reduction and software reuse?
Cleanup.
Can you please stop arguing about review feedback that is clearly right? This is not fixing anything. The Fixes tag is used to decide if something needs a backport. And every backport has a chance for a regression. So adding a Fixes tag to something that is not fixing a bug is actually hurting.
Quoted 10 lines · Christian Borntraeger
Quoted 7 lines · Markus Elfring
Quoted 4 lines
Quoted 4 lines
Reuse existing functionality from
memdup_user()instead of keeping duplicate source code.Generated by:
scripts/coccinelle/api/memdup_user.cocci…
Quoted 2 lines
Quoted 1 line
Fixes f2bbc96e7cfad3891b7bf9bd3e566b9b7ab4553d ("s390/pkey: add CCA AES cipher key support")
Quoted 8 lines
Quoted 3 lines
Quoted 1 line
This doesn't fix anything
How would you categorise the proposed source code reduction and software reuse?
Cleanup.
Can you please stop arguing about review feedback that is clearly right? This is not fixing anything. The Fixes tag is used to decide if something needs a backport.
Fixes tags are independent from backports. If you want a backport you should CC stable.
Fixes tags are useful for a bunch of things like when you're reviewing a patch you can look at the original commit to see what was intended. Also we can do automated analysis to see what sort of commits introduce bugs (did they spend time in linux-next etc).
regards,
dan carpenter
Quoted 15 lines · Dan Carpenter
Quoted 14 lines · Christian Borntraeger
Quoted 10 lines · Markus Elfring
Quoted 4 lines
Quoted 4 lines
Reuse existing functionality from
memdup_user()instead of keeping duplicate source code.Generated by:
scripts/coccinelle/api/memdup_user.cocci…
Quoted 3 lines
Quoted 1 line
Fixes f2bbc96e7cfad3891b7bf9bd3e566b9b7ab4553d ("s390/pkey: add CCA AES cipher key support")This doesn't fix anything
How would you categorise the proposed source code reduction and software reuse?
Quoted 7 lines
Quoted 4 lines
Cleanup.
Can you please stop arguing about review feedback that is clearly right? This is not fixing anything. The Fixes tag is used to decide if something needs a backport.
Fixes tags are independent from backports. If you want a backport you should CC stable.
I agree, but a Fixes tag increases the likelyhood of automatic backports anyway. (e.g. some distro kernel maintainers check for this tag).
PATCH v2 1/1 s390/pkey: Use memdup_user() rather than duplicating its implementation
In reply to Joe PerchesFrom: Markus Elfring <[email protected]>
Date: Thu, 7 Nov 2019 10:40:18 +0100
Reuse existing functionality from memdup_user() instead of keeping duplicate source code.
Generated by: scripts/coccinelle/api/memdup_user.cocci
Delete local variables which became unnecessary with this refactoring in two function implementations.
---
v2:
Further changes were requested by Joe Perches.
https://lore.kernel.org/r/[email protected]/
* The proposed usage of two conditional operators was replaced by an other code structure.
* A sanity check was adjusted for the function “_copy_apqns_from_user”.
drivers/s390/crypto/pkey_api.c | 26 ++++---------------------- 1 file changed, 4 insertions(+), 22 deletions(-)
drivers/s390/crypto/pkey_api.c +4 -22
@@ -715,36 +715,18 @@ static int pkey_apqns4keytype(enum pkey_key_type ktype,static void *_copy_key_from_user (void __user *ukey,size_t keylen) { -void *kkey; -if (!ukey || keylen <MINKEYBLOBSIZE || keylen >KEYBLOBBUFSIZE )return ERR_PTR (-EINVAL ); - kkey =kmalloc (keylen,GFP_KERNEL ); -if (!kkey) -return ERR_PTR (-ENOMEM ); -if (copy_from_user (kkey, ukey, keylen)) { -kfree (kkey); -return ERR_PTR (-EFAULT ); - } -return kkey; +return memdup_user (ukey, keylen); }static void *_copy_apqns_from_user (void __user *uapqns,size_t nr_apqns) { -void *kapqns =NULL ; -size_t nbytes; - -if (uapqns && nr_apqns >0 ) { - nbytes = nr_apqns *sizeof (struct pkey_apqn ); - kapqns =kmalloc (nbytes,GFP_KERNEL ); -if (!kapqns) -return ERR_PTR (-ENOMEM ); -if (copy_from_user (kapqns, uapqns, nbytes)) -return ERR_PTR (-EFAULT ); - } +if (!uapqns || nr_apqns <=0 ) +return NULL ; -return kapqns; +return memdup_user (uapqns, nr_apqns *sizeof (struct pkey_apqn )); } static long pkey_unlocked_ioctl(struct file *filp, unsigned int cmd,
--
2.24.0
Quoted 6 lines · Markus Elfring
From: Markus Elfring <[email protected]>
Date: Thu, 7 Nov 2019 10:40:18 +0100Reuse existing functionality from
memdup_user()instead of keeping duplicate source code.
Quoted 6 lines
Generated by:
scripts/coccinelle/api/memdup_user.cocciDelete local variables which became unnecessary with this refactoring in two function implementations.
Fixes f2bbc96e7cfad3891b7bf9bd3e566b9b7ab4553d ("s390/pkey: add CCA AES cipher key support")
With that patch description, the Fixes tag is wrong...but (see below)
Quoted 28 lines
Signed-off-by Markus Elfring <[email protected]>---
v2:
Further changes were requested by Joe Perches.
https://lore.kernel.org/r/[email protected]/* The proposed usage of two conditional operators was replaced by an other code structure.
* A sanity check was adjusted for the function “_copy_apqns_from_user”.
drivers/s390/crypto/pkey_api.c | 26 ++++---------------------- 1 file changed, 4 insertions(+), 22 deletions(-)drivers/s390/crypto/pkey_api.c +0
-2@@ -715,36 +715,18 @@ static int pkey_apqns4keytype(enum pkey_key_type ktype,static void *_copy_key_from_user (void __user *ukey,size_t keylen) { -void *kkey; -if (!ukey || keylen <MINKEYBLOBSIZE || keylen >KEYBLOBBUFSIZE )return ERR_PTR (-EINVAL );
drivers/s390/crypto/pkey_api.c static int pkey_apqns4keytype(enum pkey_key_type ktype, · line 721
Quoted 10 lines
drivers/s390/crypto/pkey_api.c +1
-8- kkey =kmalloc (keylen,GFP_KERNEL ); -if (!kkey) -return ERR_PTR (-ENOMEM ); -if (copy_from_user (kkey, ukey, keylen)) { -kfree (kkey); -return ERR_PTR (-EFAULT ); - } -return kkey; +return memdup_user (ukey, keylen);
This part looks good
drivers/s390/crypto/pkey_api.c static int pkey_apqns4keytype(enum pkey_key_type ktype, · line 725
Quoted 4 lines
drivers/s390/crypto/pkey_api.c +0
-0}static void *_copy_apqns_from_user (void __user *uapqns,size_t nr_apqns) {
This part below is not an equivalent replacement. In fact you are fixing a bug here...
drivers/s390/crypto/pkey_api.c static int pkey_apqns4keytype(enum pkey_key_type ktype, · line 743
Quoted 9 lines
drivers/s390/crypto/pkey_api.c +0
-9-void *kapqns =NULL ; -size_t nbytes; - -if (uapqns && nr_apqns >0 ) { - nbytes = nr_apqns *sizeof (struct pkey_apqn ); - kapqns =kmalloc (nbytes,GFP_KERNEL ); -if (!kapqns) -return ERR_PTR (-ENOMEM ); -if (copy_from_user (kapqns, uapqns, nbytes))
.... here we would need to kfree kapqns, but we do not. So this is
a memory leak. Isnt it?
So indeed this is fixing something. But please rework your the patch description accordingly.
Quoted 15 lines
drivers/s390/crypto/pkey_api.c +3
-3-return ERR_PTR (-EFAULT ); - } +if (!uapqns || nr_apqns <=0 ) +return NULL ; -return kapqns; +return memdup_user (uapqns, nr_apqns *sizeof (struct pkey_apqn )); }static long pkey_unlocked_ioctl(struct file *filp, unsigned int cmd,
--
2.24.0
Quoted 11 lines
Quoted 9 lines
Reuse existing functionality from
memdup_user()instead of keeping duplicate source code.Generated by:
scripts/coccinelle/api/memdup_user.cocciDelete local variables which became unnecessary with this refactoring in two function implementations.
Fixes f2bbc96e7cfad3891b7bf9bd3e566b9b7ab4553d ("s390/pkey: add CCA AES cipher key support")With that patch description, the Fixes tag is wrong...but (see below)
I wonder about such a conclusion together with your subsequent feedback.
Quoted 4 lines
Quoted 2 lines
static void *_copy_apqns_from_user(void
__user*uapqns,size_tnr_apqns) {This part below is not an equivalent replacement.
The shown refactoring provides also different run time characteristics, doesn't it?
Quoted 1 line
In fact you are fixing a bug here...
Thanks for your acknowledgement.
Quoted 4 lines
Quoted 4 lines
drivers/s390/crypto/pkey_api.c +0
-4-void *kapqns =NULL ; -size_t nbytes; - -if (uapqns && nr_apqns >0 ) {
Quoted 8 lines
drivers/s390/crypto/pkey_api.c static int pkey_apqns4keytype(enum pkey_key_type ktype, · line 743
Quoted 5 lines
drivers/s390/crypto/pkey_api.c +0
-5- nbytes = nr_apqns *sizeof (struct pkey_apqn ); - kapqns =kmalloc (nbytes,GFP_KERNEL ); -if (!kapqns) -return ERR_PTR (-ENOMEM ); -if (copy_from_user (kapqns, uapqns, nbytes)).... here we would need to kfree kapqns, but we do not. So this is
a memory leak. Isnt it?
This is another undesirable software weakness because of incomplete exception handling in the previous copy approach.
Quoted 2 lines
So indeed this is fixing something. But please rework your the patch description accordingly.
Can the final committer pick the opportunity up to extend the change description another bit?
Quoted 6 lines
drivers/s390/crypto/pkey_api.c static int pkey_apqns4keytype(enum pkey_key_type ktype, · line 730
Quoted 6 lines
drivers/s390/crypto/pkey_api.c +3
-1+if (!uapqns || nr_apqns <=0 ) +return NULL ; -return kapqns; +return memdup_user (uapqns, nr_apqns *sizeof (struct pkey_apqn )); }
Would you like to add any tags for the presented software improvement?
Regards,
Markus
Quoted 5 lines · Markus Elfring
Quoted 5 lines
Quoted 5 lines
Reuse existing functionality from
memdup_user()instead of keeping duplicate source code.Generated by:
scripts/coccinelle/api/memdup_user.cocci
Quoted 8 lines
Quoted 6 lines
Quoted 4 lines
Delete local variables which became unnecessary with this refactoring in two function implementations.
Fixes f2bbc96e7cfad3891b7bf9bd3e566b9b7ab4553d ("s390/pkey: add CCA AES cipher key support")With that patch description, the Fixes tag is wrong...but (see below)
I wonder about such a conclusion together with your subsequent feedback.
Please try to read and understand what other people write. My point was that your patch description only talks about refactoring and avoiding code duplication. So you do not claim to have fixed anything. You claim to have refactored things to avoid code duplication. And no, refactoring is NOT a fix.
That fact that you fix a bug was obviously just by accident. So you have not even noticed that your change was actually chaning the logical flow of the code.
Now: When you change the patch description explaining what you fix, a Fixes tag is appropriate.
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Reuse existing functionality from
memdup_user()instead of keeping duplicate source code.Generated by:
scripts/coccinelle/api/memdup_user.cocciDelete local variables which became unnecessary with this refactoring in two function implementations.
Quoted 7 lines
Quoted 5 lines
Quoted 3 lines
Quoted 1 line
Fixes f2bbc96e7cfad3891b7bf9bd3e566b9b7ab4553d ("s390/pkey: add CCA AES cipher key support")With that patch description, the Fixes tag is wrong...but (see below)
I wonder about such a conclusion together with your subsequent feedback.
Please try to read and understand what other people write.
I am also trying as usual.
Quoted 2 lines
My point was that your patch description only talks about refactoring and avoiding code duplication.
These implementation details are mentioned.
Quoted 1 line
So you do not claim to have fixed anything.
We have got a different understanding for the provided wording.
Quoted 1 line
You claim to have refactored things to avoid code duplication.
The reused code can reduce the probability for programming mistakes, can't it?
Quoted 1 line
And no, refactoring is NOT a fix.
Software development opinions vary around such a view, don't they?
Quoted 1 line
That fact that you fix a bug was obviously just by accident.
I can follow this view to some degree.
Quoted 2 lines
So you have not even noticed that your change was actually chaning the logical flow of the code.
I suggested to improve two function implementations.
Quoted 2 lines
Now: When you change the patch description explaining what you fix, a Fixes tag is appropriate.
Can such a disagreement be resolved by adding the information to the change description that an incomplete exception handling (which can trigger a memory leak) should be replaced by hopefully better functionality?
Regards,
Markus
Quoted 16 lines · Markus Elfring
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Reuse existing functionality from
memdup_user()instead of keeping duplicate source code.Generated by:
scripts/coccinelle/api/memdup_user.cocciDelete local variables which became unnecessary with this refactoring in two function implementations.
Quoted 7 lines
Quoted 5 lines
Quoted 3 lines
Quoted 1 line
Fixes f2bbc96e7cfad3891b7bf9bd3e566b9b7ab4553d ("s390/pkey: add CCA AES cipher key support")With that patch description, the Fixes tag is wrong...but (see below)
I wonder about such a conclusion together with your subsequent feedback.
Please try to read and understand what other people write.
Quoted 7 lines
I am also trying as usual.
Quoted 2 lines
My point was that your patch description only talks about refactoring and avoiding code duplication.
These implementation details are mentioned.
Exactly and my point is that the main value of your patch is not the refactoring, but the fact that your refactoring uncovered an existing memory leak. The refactoring itself is usually not a fix.
So can you just redo the patch with a new patch description ala,
refactoring and reuse. While doing this this also uncovered a real code bug (memory leak) that is fixed by the refactoring.
And please do that without continue this discussion,
PATCH v3 1/1 s390/pkey: Use memdup_user() rather than duplicating its implementation
From: Markus Elfring <[email protected]>
Date: Fri, 8 Nov 2019 17:50:22 +0100
Reuse existing functionality from memdup_user() instead of keeping duplicate source code.
Generated by: scripts/coccinelle/api/memdup_user.cocci
* The function "_copy_apqns_from_user" contained a memory leak because of a missing function call "kfree(kapqns)" for an if branch.
Thus complete the exception handling by this code replacement.
* Delete local variables which became unnecessary with this refactoring in two function implementations.
---
v3:
An adjustment was requested by Christian Bornträger for the change description.
https://lore.kernel.org/r/[email protected]/
v2:
Further changes were requested by Joe Perches.
https://lore.kernel.org/r/[email protected]/
* The proposed usage of two conditional operators was replaced by an other code structure.
* A sanity check was adjusted for the function “_copy_apqns_from_user”.
drivers/s390/crypto/pkey_api.c | 26 ++++---------------------- 1 file changed, 4 insertions(+), 22 deletions(-)
drivers/s390/crypto/pkey_api.c +4 -22
@@ -715,36 +715,18 @@ static int pkey_apqns4keytype(enum pkey_key_type ktype,static void *_copy_key_from_user (void __user *ukey,size_t keylen) { -void *kkey; -if (!ukey || keylen <MINKEYBLOBSIZE || keylen >KEYBLOBBUFSIZE )return ERR_PTR (-EINVAL ); - kkey =kmalloc (keylen,GFP_KERNEL ); -if (!kkey) -return ERR_PTR (-ENOMEM ); -if (copy_from_user (kkey, ukey, keylen)) { -kfree (kkey); -return ERR_PTR (-EFAULT ); - } -return kkey; +return memdup_user (ukey, keylen); }static void *_copy_apqns_from_user (void __user *uapqns,size_t nr_apqns) { -void *kapqns =NULL ; -size_t nbytes; - -if (uapqns && nr_apqns >0 ) { - nbytes = nr_apqns *sizeof (struct pkey_apqn ); - kapqns =kmalloc (nbytes,GFP_KERNEL ); -if (!kapqns) -return ERR_PTR (-ENOMEM ); -if (copy_from_user (kapqns, uapqns, nbytes)) -return ERR_PTR (-EFAULT ); - } +if (!uapqns || nr_apqns <=0 ) +return NULL ; -return kapqns; +return memdup_user (uapqns, nr_apqns *sizeof (struct pkey_apqn )); } static long pkey_unlocked_ioctl(struct file *filp, unsigned int cmd,
--
2.24.0
Quoted 12 lines · Markus Elfring
From: Markus Elfring <[email protected]>
Date: Fri, 8 Nov 2019 17:50:22 +0100Reuse existing functionality from
memdup_user()instead of keeping duplicate source code.Generated by:
scripts/coccinelle/api/memdup_user.cocci* The function "
_copy_apqns_from_user" contained a memory leak because of a missing function call "kfree(kapqns)" for an if branch.
Quoted 7 lines
Thus complete the exception handling by this code replacement.
* Delete local variables which became unnecessary with this refactoring in two function implementations.
Fixes f2bbc96e7cfad3891b7bf9bd3e566b9b7ab4553d ("s390/pkey: add CCA AES cipher key support")Signed-off-by Markus Elfring <[email protected]>
You were sending this from a different email address. Can you use the same for the sender and the signoff?
Can you also change the subject to indicate the "fix". e.g. something like
s390/pkey: fix memory leak in error case by using memdup_user() rather than open coding
Quoted 2 lines
Quoted 2 lines
From: Markus Elfring <[email protected]>
Date: Fri, 8 Nov 2019 17:50:22 +0100
…
Quoted 4 lines
Quoted 2 lines
Fixes f2bbc96e7cfad3891b7bf9bd3e566b9b7ab4553d ("s390/pkey: add CCA AES cipher key support")Signed-off-by Markus Elfring <[email protected]>You were sending this from a different email address.
Yes.
Quoted 1 line
Can you use the same for the sender and the signoff?
I would prefer to use the other email address (for a while).
Quoted 3 lines
Can you also change the subject to indicate the "fix". e.g. something like
s390/pkey: fix memory leak in error case by using
memdup_user()rather than open coding
Does this change request indicate also a need to split the software update between the discussed two function implementations?
Regards,
Markus
Quoted 6 lines · Markus Elfring
Quoted 2 lines
Quoted 2 lines
From: Markus Elfring <[email protected]>
Date: Fri, 8 Nov 2019 17:50:22 +0100…
Quoted 3 lines
Quoted 2 lines
Fixes f2bbc96e7cfad3891b7bf9bd3e566b9b7ab4553d ("s390/pkey: add CCA AES cipher key support")Signed-off-by Markus Elfring <[email protected]>
Quoted 8 lines
Quoted 1 line
You were sending this from a different email address.
Yes.
Quoted 1 line
Can you use the same for the sender and the signoff?
I would prefer to use the other email address (for a while).
The signoff is there to track the patch flow so I prefer that both addresses match.
Quoted 6 lines
Quoted 3 lines
Can you also change the subject to indicate the "fix". e.g. something like
s390/pkey: fix memory leak in error case by using
memdup_user()rather than open codingDoes this change request indicate also a need to split the software update between the discussed two function implementations?
No, I just want to have the word "fix" in the subject.
If you are OK with changing the sign-off to your web.de address I can do both changes when applying.
You can answer with
Signed-off-by: <your web.de address>
as approval.
Quoted 1 line
No, I just want to have the word "fix" in the subject.
How do you think about to use the preferred subject in your final commit directly? (Do you insist on sending a fourth patch variant?)
Quoted 1 line
If you are OK with changing the sign-off to your web.de address
Does hinder you anything from continuing to use the previous known email address?
Regards,
Markus
Quoted 9 lines · Markus Elfring
Quoted 1 line
No, I just want to have the word "fix" in the subject.
How do you think about to use the preferred subject in your final commit directly? (Do you insist on sending a fourth patch variant?)
Quoted 1 line
If you are OK with changing the sign-off to your web.de address
Does hinder you anything from continuing to use the previous known email address?
Can you at least send a mail from sourceforge address with the Signed-off-by? The Sign-off is meant to keep track of flow.
Quoted 3 lines
Quoted 1 line
Does hinder you anything from continuing to use the previous known email address?
Can you at least send a mail from sourceforge address with the Signed-off-by?
Not any more (for a while).
Message filter systems got difficulties with email redirection services.
Quoted 1 line
The Sign-off is meant to keep track of flow.
I find the provided tag still fine.
Regards,
Markus
Quoted 5 lines · Markus Elfring
Quoted 3 lines
Quoted 1 line
Does hinder you anything from continuing to use the previous known email address?
Can you at least send a mail from sourceforge address with the Signed-off-by?
Not any more (for a while).
Then I will not apply that patch with that email and signoff.
Quoted 7 lines
Quoted 5 lines
Quoted 3 lines
Quoted 1 line
Does hinder you anything from continuing to use the previous known email address?
Can you at least send a mail from sourceforge address with the Signed-off-by?
Not any more (for a while).
Then I will not apply that patch with that email and signoff.
Why do you find the information “Signed-off-by: Markus Elfring <[email protected]>” inappropriate (at the moment)?
Regards,
Markus
Quoted 4 lines · Markus Elfring
Quoted 4 lines
Quoted 4 lines
Quoted 3 lines
Quoted 1 line
Does hinder you anything from continuing to use the previous known email address?
Can you at least send a mail from sourceforge address with the Signed-off-by?
Quoted 8 lines
Quoted 3 lines
Quoted 1 line
Not any more (for a while).
Then I will not apply that patch with that email and signoff.
Why do you find the information “Signed-off-by: Markus Elfring <[email protected]>” inappropriate (at the moment)?
Because I am not going to add this email as the author of the patch when you are not able to send emails from that address.
Quoted 4 lines
Because I am not going to add this email as the author of the patch when you are not able to send emails from that address.
I find it more important that messages can still be sent also to the other known email address.
How often would you like to switch addresses at this place?
Regards,
Markus
PATCH v4 1/1 s390/pkey: Fix memory leak in error case by using memdup_user() rather than open coding
In reply to Christian BorntraegerDate: Mon, 11 Nov 2019 15:20:44 +0100
Reuse existing functionality from memdup_user() instead of keeping duplicate source code.
Generated by: scripts/coccinelle/api/memdup_user.cocci
* The function "_copy_apqns_from_user" contained a memory leak because of a misssing function call "kfree(kapqns)" for an if branch.
Thus complete the exception handling by this code replacement.
* Delete local variables which became unnecessary with this refactoring in two function implementations.
---
v4:
Further changes were requested by Christian Bornträger.
https://lore.kernel.org/r/[email protected]/
* An other patch subject was selected.
* An other email address was used for the tag “Signed-off-by” this time.
v3:
An adjustment was requested by Christian Bornträger for the change description.
https://lore.kernel.org/r/[email protected]/
v2:
Further changes were requested by Joe Perches.
https://lore.kernel.org/r/[email protected]/
* The proposed usage of two conditional operators was replaced by an other code structure.
* A sanity check was adjusted for the function “_copy_apqns_from_user”.
drivers/s390/crypto/pkey_api.c | 26 ++++---------------------- 1 file changed, 4 insertions(+), 22 deletions(-)
drivers/s390/crypto/pkey_api.c +4 -22
@@ -715,36 +715,18 @@ static int pkey_apqns4keytype(enum pkey_key_type ktype,static void *_copy_key_from_user (void __user *ukey,size_t keylen) { -void *kkey; -if (!ukey || keylen <MINKEYBLOBSIZE || keylen >KEYBLOBBUFSIZE )return ERR_PTR (-EINVAL ); - kkey =kmalloc (keylen,GFP_KERNEL ); -if (!kkey) -return ERR_PTR (-ENOMEM ); -if (copy_from_user (kkey, ukey, keylen)) { -kfree (kkey); -return ERR_PTR (-EFAULT ); - } -return kkey; +return memdup_user (ukey, keylen); }static void *_copy_apqns_from_user (void __user *uapqns,size_t nr_apqns) { -void *kapqns =NULL ; -size_t nbytes; - -if (uapqns && nr_apqns >0 ) { - nbytes = nr_apqns *sizeof (struct pkey_apqn ); - kapqns =kmalloc (nbytes,GFP_KERNEL ); -if (!kapqns) -return ERR_PTR (-ENOMEM ); -if (copy_from_user (kapqns, uapqns, nbytes)) -return ERR_PTR (-EFAULT ); - } +if (!uapqns || nr_apqns <=0 ) +return NULL ; -return kapqns; +return memdup_user (uapqns, nr_apqns *sizeof (struct pkey_apqn )); } static long pkey_unlocked_ioctl(struct file *filp, unsigned int cmd,
--
2.24.0
Christian Borntraeger
AppliedRe: [PATCH v4] s390/pkey: Fix memory leak in error case by using memdup_user() rather than open coding
Quoted 20 lines · Markus Elfring
Date: Mon, 11 Nov 2019 15:20:44 +0100
Reuse existing functionality from
memdup_user()instead of keeping duplicate source code.Generated by:
scripts/coccinelle/api/memdup_user.cocci* The function "
_copy_apqns_from_user" contained a memory leak because of a misssing function call "kfree(kapqns)" for an if branch.Thus complete the exception handling by this code replacement.
* Delete local variables which became unnecessary with this refactoring in two function implementations.
Fixes f2bbc96e7cfad3891b7bf9bd3e566b9b7ab4553d ("s390/pkey: add CCA AES cipher key support")Signed-off-by Markus Elfring <[email protected]>---
Quoted 7 lines
v4:
Further changes were requested by Christian Bornträger.
https://lore.kernel.org/r/[email protected]/* An other patch subject was selected.
* An other email address was used for the tag “Signed-off-by” this time.
applied. [...]
drivers/s390/crypto/pkey_api.c static int pkey_apqns4keytype(enum pkey_key_type ktype, · line 726
Quoted 1 line
drivers/s390/crypto/pkey_api.c +1
-0+if (!uapqns || nr_apqns <=0 )
While applying I changed that to
if (!uapqns || nr_apqns = 0)
as nr_apqns is size_t and thus unsigned.
Re: [v4] s390/pkey: Fix memory leak in error case by using memdup_user() rather than open coding
Quoted 1 line
applied. [...]
I find it interesting how the commit message was changed once more.
https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git/commit/?id‹57e7c852fc58a62e668a83c0fa8d9246131803
("s390/pkey: use memdup_user() to simplify code")
Regards,
Markus