netfilter: nf_osf: avoid passing pointer to local var
Subsystems (3)
PATCH 1/1 netfilter: nf_osf: avoid passing pointer to local var
gcc-10 points out that a code path exists where a pointer to a stack variable may be passed back to the caller:
net/netfilter/nfnetlink_osf.c: In function 'nf_osf_hdr_ctx_init':
cc1: warning: function may return address of local variable [-Wreturn-local-addr] net/netfilter/nfnetlink_osf.c:171:16: note: declared here
171 | struct tcphdr _tcph;
| ^~~~~I am not sure whether this can happen in practice, but moving the variable declaration into the callers avoids the problem.
--- net/netfilter/nfnetlink_osf.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-)
net/netfilter/nfnetlink_osf.c +7 -5
@@ -165,12 +165,12 @@ static bool nf_osf_match_one(const struct sk_buff *skb,static const struct tcphdr *nf_osf_hdr_ctx_init (struct nf_osf_hdr_ctx *ctx,const struct sk_buff *skb,const struct iphdr *ip, -unsigned char *opts) +unsigned char *opts, +struct tcphdr *_tcph) {const struct tcphdr *tcp; -struct tcphdr _tcph; - tcp =skb_header_pointer (skb,ip_hdrlen (skb),sizeof (struct tcphdr ), &_tcph); + tcp =skb_header_pointer (skb,ip_hdrlen (skb),sizeof (struct tcphdr ), _tcph);if (!tcp)return NULL ;
@@ -205,10 +205,11 @@ nf_osf_match(const struct sk_buff *skb, u_int8_t family,int fmatch =FMATCH_WRONG ;struct nf_osf_hdr_ctx ctx;const struct tcphdr *tcp; +struct tcphdr _tcph;memset (&ctx,0 ,sizeof (ctx)); - tcp =nf_osf_hdr_ctx_init (&ctx, skb, ip, opts); + tcp =nf_osf_hdr_ctx_init (&ctx, skb, ip, opts, &_tcph);if (!tcp)return false;
@@ -265,10 +266,11 @@ bool nf_osf_find(const struct sk_buff *skb,const struct nf_osf_finger *kf;struct nf_osf_hdr_ctx ctx;const struct tcphdr *tcp; +struct tcphdr _tcph;memset (&ctx,0 ,sizeof (ctx)); - tcp =nf_osf_hdr_ctx_init (&ctx, skb, ip, opts); + tcp =nf_osf_hdr_ctx_init (&ctx, skb, ip, opts, &_tcph);if (!tcp)return false;
Signature · 1 line
2.26.0
Quoted 11 lines · Arnd Bergmann
gcc-10 points out that a code path exists where a pointer to a stack variable may be passed back to the caller:
net/netfilter/nfnetlink_osf.c: In function 'nf_osf_hdr_ctx_init':
cc1: warning: function may return address of local variable [-Wreturn-local-addr]net/netfilter/nfnetlink_osf.c:171:16: note: declared here171 | struct tcphdr _tcph; | ^~~~~I am not sure whether this can happen in practice, but moving the variable declaration into the callers avoids the problem.
LGTM, thanks Arnd.
Quoted 11 lines · Arnd Bergmann
gcc-10 points out that a code path exists where a pointer to a stack variable may be passed back to the caller:
net/netfilter/nfnetlink_osf.c: In function 'nf_osf_hdr_ctx_init':
cc1: warning: function may return address of local variable [-Wreturn-local-addr]net/netfilter/nfnetlink_osf.c:171:16: note: declared here171 | struct tcphdr _tcph; | ^~~~~I am not sure whether this can happen in practice, but moving the variable declaration into the callers avoids the problem.
Applied, thanks.