xfrm: clone XFRMA_SET_MARK during xfrm_do_migrate
Subsystems (3)
PATCH 1/3 xfrm: clone XFRMA_SET_MARK during xfrm_do_migrate
XFRMA_SET_MARK and XFRMA_SET_MARK_MASK was not cloned from the old to the new. Migrate these two attributes during XFRMA_MSG_MIGRATE
--- net/xfrm/xfrm_state.c | 1 + 1 file changed, 1 insertion(+)
net/xfrm/xfrm_state.c +1 -0
@@ -1510,6 +1510,7 @@ static struct xfrm_state *xfrm_state_clone(struct xfrm_state *orig, }memcpy (&x->mark, &orig->mark,sizeof (x->mark)); +memcpy (&x->props.smark, &orig->props.smark,sizeof (x->props.smark));if (xfrm_init_state (x) <0 ) goto error;
Signature · 1 line
2.20.1
PATCH 2/3 xfrm: clone XFRMA_REPLAY_ESN_VAL in xfrm_do_migrate
XFRMA_REPLAY_ESN_VAL was not cloned from the old to the new. Migrate this attribute during XFRMA_MSG_MIGRATE
--- include/net/xfrm.h | 16 ++++++---------- net/xfrm/xfrm_state.c | 2 +- 2 files changed, 7 insertions(+), 11 deletions(-)
include/net/xfrm.h +6 -10
@@ -1773,21 +1773,17 @@ static inline unsigned int xfrm_replay_state_esn_len(struct xfrm_replay_state_esstatic inline int xfrm_replay_clone (struct xfrm_state *x,struct xfrm_state *orig) { - x->replay_esn =kzalloc (xfrm_replay_state_esn_len (orig->replay_esn), + + x->replay_esn =kmemdup (orig->replay_esn, +xfrm_replay_state_esn_len (orig->replay_esn),GFP_KERNEL );if (!x->replay_esn)return -ENOMEM ; - - x->replay_esn->bmp_len = orig->replay_esn->bmp_len; - x->replay_esn->replay_window = orig->replay_esn->replay_window; - - x->preplay_esn =kmemdup (x->replay_esn, -xfrm_replay_state_esn_len (x->replay_esn), + x->preplay_esn =kmemdup (orig->preplay_esn, +xfrm_replay_state_esn_len (orig->preplay_esn),GFP_KERNEL ); -if (!x->preplay_esn) { -kfree (x->replay_esn); +if (!x->preplay_esn)return -ENOMEM ; - }return 0 ; }
net/xfrm/xfrm_state.c +1 -1
@@ -1522,7 +1522,7 @@ static struct xfrm_state *xfrm_state_clone(struct xfrm_state *orig, x->tfcpad = orig->tfcpad; x->replay_maxdiff = orig->replay_maxdiff; x->replay_maxage = orig->replay_maxage; - x->curlft.add_time = orig->curlft.add_time; + x->curlft = orig->curlft; x->km.state = orig->km.state; x->km.seq = orig->km.seq; x->replay = orig->replay;
Signature · 1 line
2.20.1
PATCH 3/3 xfrm: clone XFRMA_SEC_CTX during xfrm_do_migrate
In reply to Antony AntonyXFRMA_SEC_CTX was not cloned from the old to the new. Migrate this attribute during XFRMA_MSG_MIGRATE
--- net/xfrm/xfrm_state.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+)
net/xfrm/xfrm_state.c +28 -0
@@ -1441,6 +1441,30 @@ int xfrm_state_add(struct xfrm_state *x)EXPORT_SYMBOL (xfrm_state_add);#ifdef CONFIG_XFRM_MIGRATE +static inline bool clone_security (struct xfrm_state *x,struct xfrm_sec_ctx *security) +{ +struct xfrm_user_sec_ctx *uctx; +int size =sizeof (*uctx) + security->ctx_len; +int err; + + uctx =kmalloc (size,GFP_KERNEL ); +if (!uctx) +return true; + + uctx->exttype =XFRMA_SEC_CTX ; + uctx->len = size; + uctx->ctx_doi = security->ctx_doi; + uctx->ctx_alg = security->ctx_alg; + uctx->ctx_len = security->ctx_len; +memcpy (uctx +1 , security->ctx_str, security->ctx_len); + err =security_xfrm_state_alloc (x, uctx); +kfree (uctx); +if (err) +return true; + +return false; +} +static struct xfrm_state *xfrm_state_clone (struct xfrm_state *orig,struct xfrm_encap_tmpl *encap) {
@@ -1497,6 +1521,10 @@ static struct xfrm_state *xfrm_state_clone(struct xfrm_state *orig, goto error; } +if (orig->security) +if (clone_security (x, orig->security)) + goto error; +if (orig->coaddr) { x->coaddr =kmemdup (orig->coaddr,sizeof (*x->coaddr),GFP_KERNEL );
Signature · 1 line
2.20.1
Steffen Klassert
maintainerRe: [PATCH 3/3] xfrm: clone XFRMA_SEC_CTX during xfrm_do_migrate
Quoted 26 lines · Antony Antony
XFRMA_SEC_CTXwas not cloned from the old to the new. Migrate this attribute duringXFRMA_MSG_MIGRATESigned-off-by Antony Antony <[email protected]>--- net/xfrm/xfrm_state.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+)net/xfrm/xfrm_state.c +10
-0@@ -1441,6 +1441,30 @@ int xfrm_state_add(struct xfrm_state *x)EXPORT_SYMBOL (xfrm_state_add);#ifdef CONFIG_XFRM_MIGRATE +static inline bool clone_security (struct xfrm_state *x,struct xfrm_sec_ctx *security) +{ +struct xfrm_user_sec_ctx *uctx; +int size =sizeof (*uctx) + security->ctx_len; +int err; + + uctx =kmalloc (size,GFP_KERNEL ); +if (!uctx) +return true; +
net/xfrm/xfrm_state.c int xfrm_state_add(struct xfrm_state *x) · line 1463
Quoted 10 lines
net/xfrm/xfrm_state.c +10
-0+ uctx->exttype =XFRMA_SEC_CTX ; + uctx->len = size; + uctx->ctx_doi = security->ctx_doi; + uctx->ctx_alg = security->ctx_alg; + uctx->ctx_len = security->ctx_len; +memcpy (uctx +1 , security->ctx_str, security->ctx_len); + err =security_xfrm_state_alloc (x, uctx); +kfree (uctx); +if (err) +return true;
Returning 'true' on memory allocation errors is a bit odd, please return -ENOMEM instead.
Steffen Klassert
maintainerRe: [PATCH 2/3] xfrm: clone XFRMA_REPLAY_ESN_VAL in xfrm_do_migrate
In reply to Antony AntonyQuoted 46 lines · Antony Antony
XFRMA_REPLAY_ESN_VALwas not cloned from the old to the new. Migrate this attribute duringXFRMA_MSG_MIGRATESigned-off-by Antony Antony <[email protected]>--- include/net/xfrm.h | 16 ++++++---------- net/xfrm/xfrm_state.c | 2 +- 2 files changed, 7 insertions(+), 11 deletions(-)include/net/xfrm.h +6
-10@@ -1773,21 +1773,17 @@ static inline unsigned int xfrm_replay_state_esn_len(struct xfrm_replay_state_esstatic inline int xfrm_replay_clone (struct xfrm_state *x,struct xfrm_state *orig) { - x->replay_esn =kzalloc (xfrm_replay_state_esn_len (orig->replay_esn), + + x->replay_esn =kmemdup (orig->replay_esn, +xfrm_replay_state_esn_len (orig->replay_esn),GFP_KERNEL );if (!x->replay_esn)return -ENOMEM ; - - x->replay_esn->bmp_len = orig->replay_esn->bmp_len; - x->replay_esn->replay_window = orig->replay_esn->replay_window; - - x->preplay_esn =kmemdup (x->replay_esn, -xfrm_replay_state_esn_len (x->replay_esn), + x->preplay_esn =kmemdup (orig->preplay_esn, +xfrm_replay_state_esn_len (orig->preplay_esn),GFP_KERNEL ); -if (!x->preplay_esn) { -kfree (x->replay_esn); +if (!x->preplay_esn)return -ENOMEM ; - }return 0 ; }net/xfrm/xfrm_state.c +0
-0
net/xfrm/xfrm_state.c static struct xfrm_state *xfrm_state_clone(struct xfrm_state *orig, · line 1525
Quoted 5 lines
net/xfrm/xfrm_state.c +1
-1@@ -1522,7 +1522,7 @@ static struct xfrm_state *xfrm_state_clone(struct xfrm_state *orig, x->tfcpad = orig->tfcpad; x->replay_maxdiff = orig->replay_maxdiff; x->replay_maxage = orig->replay_maxage; - x->curlft.add_time = orig->curlft.add_time; + x->curlft = orig->curlft;
That change seems not to belong to this patch.
Also please add a 'Fixes' tag.
Steffen Klassert
maintainerQuoted 4 lines · Antony Antony
XFRMA_SET_MARKandXFRMA_SET_MARK_MASKwas not cloned from the old to the new. Migrate these two attributes duringXFRMA_MSG_MIGRATESigned-off-by Antony Antony <[email protected]>
Please add a 'Fixes' tag so that this can be backported properly to the stable trees.
PATCH v2 1/4 xfrm: clone XFRMA_SET_MARK in xfrm_do_migrate
In reply to Antony AntonyXFRMA_SET_MARK and XFRMA_SET_MARK_MASK was not cloned from the old to the new. Migrate these two attributes during XFRMA_MSG_MIGRATE
--- net/xfrm/xfrm_state.c | 1 + 1 file changed, 1 insertion(+)
net/xfrm/xfrm_state.c +1 -0
@@ -1510,6 +1510,7 @@ static struct xfrm_state *xfrm_state_clone(struct xfrm_state *orig, }memcpy (&x->mark, &orig->mark,sizeof (x->mark)); +memcpy (&x->props.smark, &orig->props.smark,sizeof (x->props.smark));if (xfrm_init_state (x) <0 ) goto error;
Signature · 1 line
2.20.1
PATCH v2 2/4 xfrm: clone XFRMA_REPLAY_ESN_VAL in xfrm_do_migrate
In reply to Antony AntonyXFRMA_REPLAY_ESN_VAL was not cloned completely from the old to the new. Migrate this attribute during XFRMA_MSG_MIGRATE
v1->v2:
- move curleft cloning to a seperate patch
--- include/net/xfrm.h | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-)
include/net/xfrm.h +6 -10
@@ -1773,21 +1773,17 @@ static inline unsigned int xfrm_replay_state_esn_len(struct xfrm_replay_state_esstatic inline int xfrm_replay_clone (struct xfrm_state *x,struct xfrm_state *orig) { - x->replay_esn =kzalloc (xfrm_replay_state_esn_len (orig->replay_esn), + + x->replay_esn =kmemdup (orig->replay_esn, +xfrm_replay_state_esn_len (orig->replay_esn),GFP_KERNEL );if (!x->replay_esn)return -ENOMEM ; - - x->replay_esn->bmp_len = orig->replay_esn->bmp_len; - x->replay_esn->replay_window = orig->replay_esn->replay_window; - - x->preplay_esn =kmemdup (x->replay_esn, -xfrm_replay_state_esn_len (x->replay_esn), + x->preplay_esn =kmemdup (orig->preplay_esn, +xfrm_replay_state_esn_len (orig->preplay_esn),GFP_KERNEL ); -if (!x->preplay_esn) { -kfree (x->replay_esn); +if (!x->preplay_esn)return -ENOMEM ; - }return 0 ; }
Signature · 1 line
2.20.1
PATCH v2 3/4 xfrm: clone XFRMA_SEC_CTX in xfrm_do_migrate
In reply to Antony AntonyXFRMA_SEC_CTX was not cloned from the old to the new. Migrate this attribute during XFRMA_MSG_MIGRATE
v1->v2:
- return -ENOMEM on error
--- net/xfrm/xfrm_state.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+)
net/xfrm/xfrm_state.c +28 -0
@@ -1441,6 +1441,30 @@ int xfrm_state_add(struct xfrm_state *x)EXPORT_SYMBOL (xfrm_state_add);#ifdef CONFIG_XFRM_MIGRATE +static inline bool clone_security (struct xfrm_state *x,struct xfrm_sec_ctx *security) +{ +struct xfrm_user_sec_ctx *uctx; +int size =sizeof (*uctx) + security->ctx_len; +int err; + + uctx =kmalloc (size,GFP_KERNEL ); +if (!uctx) +return -ENOMEM ; + + uctx->exttype =XFRMA_SEC_CTX ; + uctx->len = size; + uctx->ctx_doi = security->ctx_doi; + uctx->ctx_alg = security->ctx_alg; + uctx->ctx_len = security->ctx_len; +memcpy (uctx +1 , security->ctx_str, security->ctx_len); + err =security_xfrm_state_alloc (x, uctx); +kfree (uctx); +if (err) +return err; + +return 0 ; +} +static struct xfrm_state *xfrm_state_clone (struct xfrm_state *orig,struct xfrm_encap_tmpl *encap) {
@@ -1497,6 +1521,10 @@ static struct xfrm_state *xfrm_state_clone(struct xfrm_state *orig, goto error; } +if (orig->security) +if (clone_security (x, orig->security)) + goto error; +if (orig->coaddr) { x->coaddr =kmemdup (orig->coaddr,sizeof (*x->coaddr),GFP_KERNEL );
Signature · 1 line
2.20.1
PATCH v2 4/4 xfrm: clone whole liftime_cur structure in xfrm_do_migrate
In reply to Antony AntonyWhen we clone state only add_time was cloned. It missed values like bytes, packets. Now clone the all members of the structure.
--- net/xfrm/xfrm_state.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/xfrm/xfrm_state.c +1 -1
@@ -1550,7 +1550,7 @@ static struct xfrm_state *xfrm_state_clone(struct xfrm_state *orig, x->tfcpad = orig->tfcpad; x->replay_maxdiff = orig->replay_maxdiff; x->replay_maxage = orig->replay_maxage; - x->curlft.add_time = orig->curlft.add_time; + x->curlft = orig->curlft; x->km.state = orig->km.state; x->km.seq = orig->km.seq; x->replay = orig->replay;
Signature · 1 line
2.20.1
Steffen Klassert
maintainerRe: [PATCH v2 3/4] xfrm: clone XFRMA_SEC_CTX in xfrm_do_migrate
In reply to Antony AntonyQuoted 19 lines · Antony Antony
XFRMA_SEC_CTXwas not cloned from the old to the new. Migrate this attribute duringXFRMA_MSG_MIGRATE
v1->v2:
- return-ENOMEMon errorFixes 80c9abaabf42 ("[XFRM]: Extension for dynamic update of endpoint address(es)")Signed-off-by Antony Antony <[email protected]>--- net/xfrm/xfrm_state.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+)net/xfrm/xfrm_state.c +0
-0@@ -1441,6 +1441,30 @@ int xfrm_state_add(struct xfrm_state *x)EXPORT_SYMBOL (xfrm_state_add);
net/xfrm/xfrm_state.c int xfrm_state_add(struct xfrm_state *x) · line 1452
Quoted 10 lines
net/xfrm/xfrm_state.c +9
-0#ifdef CONFIG_XFRM_MIGRATE +static inline bool clone_security (struct xfrm_state *x,struct xfrm_sec_ctx *security) +{ +struct xfrm_user_sec_ctx *uctx; +int size =sizeof (*uctx) + security->ctx_len; +int err; + + uctx =kmalloc (size,GFP_KERNEL ); +if (!uctx) +return -ENOMEM ;
Now that this function returns error values, it should be of type 'int' not 'bool'.
Steffen Klassert
maintainerRe: [PATCH v2 4/4] xfrm: clone whole liftime_cur structure in xfrm_do_migrate
In reply to Antony AntonyQuoted 14 lines · Antony Antony
When we clone state only
add_timewas cloned. It missed values like bytes, packets. Now clone the all members of the structure.Fixes 80c9abaabf42 ("[XFRM]: Extension for dynamic update of endpoint address(es)")Signed-off-by Antony Antony <[email protected]>--- net/xfrm/xfrm_state.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)net/xfrm/xfrm_state.c +0
-0
net/xfrm/xfrm_state.c static struct xfrm_state *xfrm_state_clone(struct xfrm_state *orig, · line 1553
Quoted 5 lines
net/xfrm/xfrm_state.c +1
-1@@ -1550,7 +1550,7 @@ static struct xfrm_state *xfrm_state_clone(struct xfrm_state *orig, x->tfcpad = orig->tfcpad; x->replay_maxdiff = orig->replay_maxdiff; x->replay_maxage = orig->replay_maxage; - x->curlft.add_time = orig->curlft.add_time; + x->curlft = orig->curlft;
You should use memcpy if you want to copy the whole structure.
PATCH v3 1/4 xfrm: clone XFRMA_SET_MARK in xfrm_do_migrate
In reply to Antony AntonyXFRMA_SET_MARK and XFRMA_SET_MARK_MASK was not cloned from the old to the new. Migrate these two attributes during XFRMA_MSG_MIGRATE
--- net/xfrm/xfrm_state.c | 1 + 1 file changed, 1 insertion(+)
net/xfrm/xfrm_state.c +1 -0
@@ -1510,6 +1510,7 @@ static struct xfrm_state *xfrm_state_clone(struct xfrm_state *orig, }memcpy (&x->mark, &orig->mark,sizeof (x->mark)); +memcpy (&x->props.smark, &orig->props.smark,sizeof (x->props.smark));if (xfrm_init_state (x) <0 ) goto error;
Signature · 1 line
2.20.1
PATCH v3 2/4 xfrm: clone XFRMA_REPLAY_ESN_VAL in xfrm_do_migrate
In reply to Antony AntonyXFRMA_REPLAY_ESN_VAL was not cloned completely from the old to the new. Migrate this attribute during XFRMA_MSG_MIGRATE
v1->v2:
- move curleft cloning to a separate patch
--- include/net/xfrm.h | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-)
include/net/xfrm.h +6 -10
@@ -1773,21 +1773,17 @@ static inline unsigned int xfrm_replay_state_esn_len(struct xfrm_replay_state_esstatic inline int xfrm_replay_clone (struct xfrm_state *x,struct xfrm_state *orig) { - x->replay_esn =kzalloc (xfrm_replay_state_esn_len (orig->replay_esn), + + x->replay_esn =kmemdup (orig->replay_esn, +xfrm_replay_state_esn_len (orig->replay_esn),GFP_KERNEL );if (!x->replay_esn)return -ENOMEM ; - - x->replay_esn->bmp_len = orig->replay_esn->bmp_len; - x->replay_esn->replay_window = orig->replay_esn->replay_window; - - x->preplay_esn =kmemdup (x->replay_esn, -xfrm_replay_state_esn_len (x->replay_esn), + x->preplay_esn =kmemdup (orig->preplay_esn, +xfrm_replay_state_esn_len (orig->preplay_esn),GFP_KERNEL ); -if (!x->preplay_esn) { -kfree (x->replay_esn); +if (!x->preplay_esn)return -ENOMEM ; - }return 0 ; }
Signature · 1 line
2.20.1
PATCH v3 3/4 xfrm: clone XFRMA_SEC_CTX in xfrm_do_migrate
In reply to Antony AntonyXFRMA_SEC_CTX was not cloned from the old to the new. Migrate this attribute during XFRMA_MSG_MIGRATE
v1->v2:
- return -ENOMEM on errorv2->v3:
- fix return type to int
--- net/xfrm/xfrm_state.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+)
net/xfrm/xfrm_state.c +28 -0
@@ -1441,6 +1441,30 @@ int xfrm_state_add(struct xfrm_state *x)EXPORT_SYMBOL (xfrm_state_add);#ifdef CONFIG_XFRM_MIGRATE +static inline int clone_security (struct xfrm_state *x,struct xfrm_sec_ctx *security) +{ +struct xfrm_user_sec_ctx *uctx; +int size =sizeof (*uctx) + security->ctx_len; +int err; + + uctx =kmalloc (size,GFP_KERNEL ); +if (!uctx) +return -ENOMEM ; + + uctx->exttype =XFRMA_SEC_CTX ; + uctx->len = size; + uctx->ctx_doi = security->ctx_doi; + uctx->ctx_alg = security->ctx_alg; + uctx->ctx_len = security->ctx_len; +memcpy (uctx +1 , security->ctx_str, security->ctx_len); + err =security_xfrm_state_alloc (x, uctx); +kfree (uctx); +if (err) +return err; + +return 0 ; +} +static struct xfrm_state *xfrm_state_clone (struct xfrm_state *orig,struct xfrm_encap_tmpl *encap) {
@@ -1497,6 +1521,10 @@ static struct xfrm_state *xfrm_state_clone(struct xfrm_state *orig, goto error; } +if (orig->security) +if (clone_security (x, orig->security)) + goto error; +if (orig->coaddr) { x->coaddr =kmemdup (orig->coaddr,sizeof (*x->coaddr),GFP_KERNEL );
Signature · 1 line
2.20.1
PATCH v3 4/4 xfrm: clone whole liftime_cur structure in xfrm_do_migrate
In reply to Antony AntonyWhen we clone state only add_time was cloned. It missed values like bytes, packets. Now clone the all members of the structure.
v1->v3:
- use memcpy to copy the entire structure
--- net/xfrm/xfrm_state.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/xfrm/xfrm_state.c +1 -1
@@ -1550,7 +1550,7 @@ static struct xfrm_state *xfrm_state_clone(struct xfrm_state *orig, x->tfcpad = orig->tfcpad; x->replay_maxdiff = orig->replay_maxdiff; x->replay_maxage = orig->replay_maxage; - x->curlft.add_time = orig->curlft.add_time; +memcpy (&x->curlft, &orig->curlft,sizeof (x->curlft)); x->km.state = orig->km.state; x->km.seq = orig->km.seq; x->replay = orig->replay;
Signature · 1 line
2.20.1
Steffen Klassert
maintainerRe: [PATCH v3 1/4] xfrm: clone XFRMA_SET_MARK in xfrm_do_migrate
In reply to Antony AntonyQuoted 5 lines · Antony Antony
XFRMA_SET_MARKandXFRMA_SET_MARK_MASKwas not cloned from the old to the new. Migrate these two attributes duringXFRMA_MSG_MIGRATEFixes 9b42c1f179a6 ("xfrm: Extend the output_mark to support input direction and masking.")Signed-off-by Antony Antony <[email protected]>
All applied, thanks Antony!