Skip to contentSkip to conversation

pull request (net): ipsec 2022-07-20

PATCH Applied Steffen Klassert 2 participants 4 messages Jul 20, 2022

Subsystems (3)
lore
Share & tools
lore

Steffen Klassert

author maintainer
#0 lore raw

cover pull request (net): ipsec 2022-07-20

1) Fix a policy refcount imbalance in xfrm_bundle_lookup. From Hangyu Hua.

2) Fix some clang -Wformat warnings.
Justin Stitt

Please pull or let me know if there are problems.

Thanks!

The following changes since commit 9f4fc18bf285f20c1498f8fcfb586fa70a070fb5:

net: usb: qmi_wwan: Add support for Cinterion MV31 with new baseline (2022-06-01 18:09:34 -0700)

are available in the Git repository at:

git://git.kernel.org/pub/scm/linux/kernel/git/klassert/ipsec.git master

for you to fetch changes up to e79b9473e9b59e83e23db9b7411c6080b5a6826d:

net: ipv4: fix clang -Wformat warnings (2022-07-12 12:58:53 +0200)

----------------------------------------------------------------
Hangyu Hua (1):
xfrm: xfrm_policy: fix a possible double xfrm_pols_put() in xfrm_bundle_lookup()

Justin Stitt (1):
net: ipv4: fix clang -Wformat warnings

 net/ipv4/ah4.c         | 2 +-
 net/ipv4/esp4.c        | 2 +-
 net/xfrm/xfrm_policy.c | 5 ++++-
 3 files changed, 6 insertions(+), 3 deletions(-)
author maintainer
#1 lore raw

PATCH 1/2 xfrm: xfrm_policy: fix a possible double xfrm_pols_put() in xfrm_bundle_lookup()

From: Hangyu Hua <[email protected]>

xfrm_policy_lookup() will call xfrm_pol_hold_rcu() to get a refcount of pols[0]. This refcount can be dropped in xfrm_expand_policies() when xfrm_expand_policies() return error. pols[0]'s refcount is balanced in here. But xfrm_bundle_lookup() will also call xfrm_pols_put() with num_pols == 1 to drop this refcount when xfrm_expand_policies() return error.

This patch also fix an illegal address access. pols[0] will save a error point when xfrm_policy_lookup fails. This lead to xfrm_pols_put to resolve an illegal address in xfrm_bundle_lookup's error path.

Fix these by setting num_pols = 0 in xfrm_expand_policies()'s error path.

Fixes 80c802f3073e ("xfrm: cache bundles instead of policies for outgoing flows")
---
 net/xfrm/xfrm_policy.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
net/xfrm/xfrm_policy.c +4 -1
index f1876ea61fdc..f1a0bab920a5 100644
@@ -2678,8 +2678,10 @@ static int xfrm_expand_policies(const struct flowi *fl, u16 family,
 		*num_xfrms = 0;
 		return 0;
 	}
-	if (IS_ERR(pols[0]))
+	if (IS_ERR(pols[0])) {
+		*num_pols = 0;
 		return PTR_ERR(pols[0]);
+	}
 
 	*num_xfrms = pols[0]->xfrm_nr;
 
@@ -2694,6 +2696,7 @@ static int xfrm_expand_policies(const struct flowi *fl, u16 family,
 		if (pols[1]) {
 			if (IS_ERR(pols[1])) {
 				xfrm_pols_put(pols, *num_pols);
+				*num_pols = 0;
 				return PTR_ERR(pols[1]);
 			}
 			(*num_pols)++;
Signature · 1 line
2.25.1
#2 lore raw

Re: [PATCH 1/2] xfrm: xfrm_policy: fix a possible double xfrm_pols_put() in xfrm_bundle_lookup()

This series was applied to netdev/net.git (master) by Steffen Klassert <[email protected]>:

Hello:

This series was applied to netdev/net.git (master) by Steffen Klassert <[email protected]>:

Quoted 10 lines · On Wed, 20 Jul 2022 10:09:11 +0200 you wrote:

From: Hangyu Hua <[email protected]>

xfrm_policy_lookup() will call xfrm_pol_hold_rcu() to get a refcount of pols[0]. This refcount can be dropped in xfrm_expand_policies() when xfrm_expand_policies() return error. pols[0]'s refcount is balanced in here. But xfrm_bundle_lookup() will also call xfrm_pols_put() with num_pols == 1 to drop this refcount when xfrm_expand_policies() return error.

[...]

Here is the summary with links:
- [1/2] xfrm: xfrm_policy: fix a possible double xfrm_pols_put() in xfrm_bundle_lookup()

    https://git.kernel.org/netdev/net/c/f85daf0e7253
  - [2/2] net: ipv4: fix clang -Wformat warnings
    https://git.kernel.org/netdev/net/c/e79b9473e9b5

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
author maintainer
#3 lore raw

PATCH 2/2 net: ipv4: fix clang -Wformat warnings

In reply to Steffen Klassert

From: Justin Stitt <[email protected]>

When building with Clang we encounter these warnings:

| net/ipv4/ah4.c:513:4: error: format specifies type 'unsigned short' but
| the argument has type 'int' [-Werror,-Wformat]
| aalg_desc->uinfo.auth.icv_fullbits / 8);
-
| net/ipv4/esp4.c:1114:5: error: format specifies type 'unsigned short'
| but the argument has type 'int' [-Werror,-Wformat]
| aalg_desc->uinfo.auth.icv_fullbits / 8);

aalg_desc->uinfo.auth.icv_fullbits is a u16 but due to default argument promotion becomes an int.

Variadic functions (printf-like) undergo default argument promotion. Documentation/core-api/printk-formats.rst specifically recommends using the promoted-to-type's format flag.

As per C11 6.3.1.1:
(https://www.open-std.org/jtc1/sc22/wg14/www/docs/n1548.pdf) If an int can represent all values of the original type ..., the value is converted to an int; otherwise, it is converted to an unsigned int. These are called the integer promotions. Thus it makes sense to change %hu to %d not only to follow this standard but to suppress the warning as well.

---
 net/ipv4/ah4.c  | 2 +-
 net/ipv4/esp4.c | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
net/ipv4/ah4.c +1 -1
index 6eea1e9e998d..f8ad04470d3a 100644
@@ -507,7 +507,7 @@ static int ah_init_state(struct xfrm_state *x)
 
 	if (aalg_desc->uinfo.auth.icv_fullbits/8 !=
 	    crypto_ahash_digestsize(ahash)) {
-		pr_info("%s: %s digestsize %u != %hu\n",
+		pr_info("%s: %s digestsize %u != %u\n",
 			__func__, x->aalg->alg_name,
 			crypto_ahash_digestsize(ahash),
 			aalg_desc->uinfo.auth.icv_fullbits / 8);
net/ipv4/esp4.c +1 -1
index b21238df3301..b694f352ce7a 100644
@@ -1108,7 +1108,7 @@ static int esp_init_authenc(struct xfrm_state *x)
 		err = -EINVAL;
 		if (aalg_desc->uinfo.auth.icv_fullbits / 8 !=
 		    crypto_aead_authsize(aead)) {
-			pr_info("ESP: %s digestsize %u != %hu\n",
+			pr_info("ESP: %s digestsize %u != %u\n",
 				x->aalg->alg_name,
 				crypto_aead_authsize(aead),
 				aalg_desc->uinfo.auth.icv_fullbits / 8);
Signature · 1 line
2.25.1