Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp3636033imm; Thu, 17 May 2018 12:00:08 -0700 (PDT) X-Google-Smtp-Source: AB8JxZr3jT5bFNAtDSbYU0J/ZQ/5V0ZSS6DbfWgZomUQNC2ZYO2x/Hb1iFHvDGlMWnMTHWJSZNVb X-Received: by 2002:a62:c81d:: with SMTP id z29-v6mr6232225pff.81.1526583608027; Thu, 17 May 2018 12:00:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1526583608; cv=none; d=google.com; s=arc-20160816; b=C/MaX3muVdYG4TpXLJSmsPEB3n7O69y/P3sRiQ3FYgbt3A8JtdQ5HqXdcMbJhUaZmW DYo/WqLET+4M/V3Goc064IwK3/+ngIAyhp8nLbNgXBZNaPeMKNRGbHwAstw8wp+rYc5C Y+WN1fO2tNx1O4iuac2lmLhL1jR4h99ONERyJvVpPA4ZBTYTFpxuZexwWoQ+gDsl9Ous 6qA2jvsq0g1wzMq1Oz662/l1SF7OawJU2rhQJ6pTnwonyGyOb/jHtTP9pkAupgYfUDey yfqycPDNR9IknNtefYcKU7vMnhsEn8xtdSLa97hWFKFymdPUKYB0061UldjUUjOxKCqR 9WiA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:arc-authentication-results; bh=EmyhgUcOxiQUJMIX0ItMs0tATnfhnpr+FP0Fy/aJg8I=; b=O67PjtRRJH/XWrDfT+X89uCdXQ440DQOnh4eYSN2VhEt0ZL+FQ233idNahjRkwEqqD RpdyRUsYaGiGonzBfjQg0LyHzs8p1ZgL7e+n3o6O6HoteokMhKPM1PCmq2WVQge2mUYa lUu2W6pJ+ql3i4e4+7PV7yKw1RgdaRzjBqCZupHJWlu6DQOzorBE4ohjGkG6HO8um/Te Lb6FgAgLdvqIMfTmSq6NpVfh33SPLPgIT2bhhU79UY7LgF4qYQpV2OiGPgW7mWduy2rY GW3npw/tkuDvOhMvkefY3jP8gxqRCiwmATcJZ6wWhyk3BvywKcISjzl3FRXTpNFvrgGi DyOg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 33-v6si5629654pls.339.2018.05.17.11.59.52; Thu, 17 May 2018 12:00:07 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751967AbeEQS7g (ORCPT + 99 others); Thu, 17 May 2018 14:59:36 -0400 Received: from gateway36.websitewelcome.com ([192.185.196.23]:48550 "EHLO gateway36.websitewelcome.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751695AbeEQS7f (ORCPT ); Thu, 17 May 2018 14:59:35 -0400 X-Greylist: delayed 1500 seconds by postgrey-1.27 at vger.kernel.org; Thu, 17 May 2018 14:59:35 EDT Received: from cm13.websitewelcome.com (cm13.websitewelcome.com [100.42.49.6]) by gateway36.websitewelcome.com (Postfix) with ESMTP id 607EB4012810B for ; Thu, 17 May 2018 13:12:46 -0500 (CDT) Received: from gator4166.hostgator.com ([108.167.133.22]) by cmsmtp with SMTP id JNOQf2CeiQUwqJNOQfj8Bi; Thu, 17 May 2018 13:12:46 -0500 X-Authority-Reason: nr=8 Received: from [187.172.56.86] (port=42258 helo=[192.168.1.70]) by gator4166.hostgator.com with esmtpsa (TLSv1.2:ECDHE-RSA-AES128-GCM-SHA256:128) (Exim 4.89_1) (envelope-from ) id 1fJNOP-003gk1-Vs; Thu, 17 May 2018 13:12:46 -0500 Subject: Re: [PATCH 1/2] bpf: sockmap, fix uninitialized variable To: John Fastabend , Alexei Starovoitov , Daniel Borkmann Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org References: <11073635016901e9e84c2f34f20d412073b26297.1526565461.git.gustavo@embeddedor.com> From: "Gustavo A. R. Silva" Message-ID: <98d55ad8-e5c8-7f1c-ea9b-940be45787d6@embeddedor.com> Date: Thu, 17 May 2018 13:12:43 -0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.7.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - gator4166.hostgator.com X-AntiAbuse: Original Domain - vger.kernel.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - embeddedor.com X-BWhitelist: no X-Source-IP: 187.172.56.86 X-Source-L: No X-Exim-ID: 1fJNOP-003gk1-Vs X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: ([192.168.1.70]) [187.172.56.86]:42258 X-Source-Auth: gustavo@embeddedor.com X-Email-Count: 10 X-Source-Cap: Z3V6aWRpbmU7Z3V6aWRpbmU7Z2F0b3I0MTY2Lmhvc3RnYXRvci5jb20= X-Local-Domain: yes Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi John, On 05/17/2018 12:27 PM, John Fastabend wrote: > On 05/17/2018 07:08 AM, Gustavo A. R. Silva wrote: >> There is a potential execution path in which variable err is >> returned without being properly initialized previously. >> >> Fix this by initializing variable err to 0. >> >> Addresses-Coverity-ID: 1468964 ("Uninitialized scalar variable") >> Fixes: e5cd3abcb31a ("bpf: sockmap, refactor sockmap routines to work >> with hashmap") >> Signed-off-by: Gustavo A. R. Silva >> --- >> kernel/bpf/sockmap.c | 2 +- >> 1 file changed, 1 insertion(+), 1 deletion(-) >> >> diff --git a/kernel/bpf/sockmap.c b/kernel/bpf/sockmap.c >> index c6de139..41b41fc 100644 >> --- a/kernel/bpf/sockmap.c >> +++ b/kernel/bpf/sockmap.c >> @@ -1713,7 +1713,7 @@ static int __sock_map_ctx_update_elem(struct bpf_map *map, >> struct smap_psock_map_entry *e = NULL; >> struct smap_psock *psock; >> bool new = false; >> - int err; >> + int err = 0; >> >> /* 1. If sock map has BPF programs those will be inherited by the >> * sock being added. If the sock is already attached to BPF programs >> > > Thanks for catching this and the quick fix. The path to hit this case > is to add a sock to a map (without a BPF program) where the sock already > has been added to another map. I don't have any tests for the case with > socks in multiple maps so I'll add some to the selftests so I remember > this case. > Glad to help. :) > The alternative fix would be to always 'return 0' at the end of the > function, but I think its probably better to init err here like above. > Yeah. I think initializing err is better in this case. > Acked-by: John Fastabend > Thank you -- Gustavo