Skip to content

Commit 30a3805

Browse files
arndbgregkh
authored andcommitted
netfilter: nf_osf: avoid passing pointer to local var
commit c165d57 upstream. 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. Fixes: 31a9c29 ("netfilter: nf_osf: add struct nf_osf_hdr_ctx") Signed-off-by: Arnd Bergmann <arnd@arndb.de> Reviewed-by: Florian Westphal <fw@strlen.de> Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 4ccbd9c commit 30a3805

1 file changed

Lines changed: 7 additions & 5 deletions

File tree

net/netfilter/nfnetlink_osf.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -165,12 +165,12 @@ static bool nf_osf_match_one(const struct sk_buff *skb,
165165
static const struct tcphdr *nf_osf_hdr_ctx_init(struct nf_osf_hdr_ctx *ctx,
166166
const struct sk_buff *skb,
167167
const struct iphdr *ip,
168-
unsigned char *opts)
168+
unsigned char *opts,
169+
struct tcphdr *_tcph)
169170
{
170171
const struct tcphdr *tcp;
171-
struct tcphdr _tcph;
172172

173-
tcp = skb_header_pointer(skb, ip_hdrlen(skb), sizeof(struct tcphdr), &_tcph);
173+
tcp = skb_header_pointer(skb, ip_hdrlen(skb), sizeof(struct tcphdr), _tcph);
174174
if (!tcp)
175175
return NULL;
176176

@@ -205,10 +205,11 @@ nf_osf_match(const struct sk_buff *skb, u_int8_t family,
205205
int fmatch = FMATCH_WRONG;
206206
struct nf_osf_hdr_ctx ctx;
207207
const struct tcphdr *tcp;
208+
struct tcphdr _tcph;
208209

209210
memset(&ctx, 0, sizeof(ctx));
210211

211-
tcp = nf_osf_hdr_ctx_init(&ctx, skb, ip, opts);
212+
tcp = nf_osf_hdr_ctx_init(&ctx, skb, ip, opts, &_tcph);
212213
if (!tcp)
213214
return false;
214215

@@ -265,10 +266,11 @@ bool nf_osf_find(const struct sk_buff *skb,
265266
const struct nf_osf_finger *kf;
266267
struct nf_osf_hdr_ctx ctx;
267268
const struct tcphdr *tcp;
269+
struct tcphdr _tcph;
268270

269271
memset(&ctx, 0, sizeof(ctx));
270272

271-
tcp = nf_osf_hdr_ctx_init(&ctx, skb, ip, opts);
273+
tcp = nf_osf_hdr_ctx_init(&ctx, skb, ip, opts, &_tcph);
272274
if (!tcp)
273275
return false;
274276

0 commit comments

Comments
 (0)