Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp2721914rwb; Thu, 17 Nov 2022 15:15:40 -0800 (PST) X-Google-Smtp-Source: AA0mqf6vZOJh27MryzkR4K7i75FJ/qtIH4n0loLTF0OWi4OH1EffU75SUqukJs2MHITG5mtyqTC3 X-Received: by 2002:a17:906:b250:b0:7b2:86d5:8b14 with SMTP id ce16-20020a170906b25000b007b286d58b14mr3951027ejb.230.1668726940629; Thu, 17 Nov 2022 15:15:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668726940; cv=none; d=google.com; s=arc-20160816; b=BC08mnd48ZM0YLhtPTE55J1Lgk+sXE8BP8a1RX96m9AI2ixfnW9Su9U/LwmUk+hLOG izUOfsj3bxMJSCEcqasQ0vJQbMfd6ZQQmcI+bsQckUEM0MXUcZ+g5HD7D5lNJthgoMah n8BJsTr9NcC6Py/rHX94iulbXoE8PjfJCRxQ7w1OcX5dOfn7UPujeDMPpL19P7iSjRqN VmrZ0c0lhiXr4usNeGVP0adkKcl6HfPQIf2p+YRLlYKHHHhWC6WniS9xi2T0vAU88qVR /RzZsHkDiPhMWuXGPsX0aunaw5HPW1EwMmAsG7LlPxnk+dOK3SqHEDTiz8kqTIw8acY3 pEsQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=oBQqoT8aYHZ0vQjXNPjZ+F7M4m+OJwx56OthzoHvy+Y=; b=YI/55AS9UuxqMZNl/GNVAhRbAoltc7zOXuNWqJb/PquvwO5gIq8MSmFx8Jnkplt6VT Qp7sR7PaSjqeXPsd4+dSx39eJXXe/BKetJYnHqy9SSFJLfM0GxTeTMngVJ3GH8bW02MV qT7umP7Hwarnb99h9CPzI4uL8lJum/eXEnk6mSnhev4jw6p2F7M4kUpQKt0+BaWJptuF 52wpsYVcNt/jv1RCKQ3OYNKnO5mYHSmuFpWK6Z2oMG0b+4wgFtArEpWfUXxQkBWf3aW5 MlFsa1fM4v9Rppz0iLTu2JjcpLODL8tEsbjTLsXwWyNEDzBHKQT3KpWKcNvA85+3OjyQ 5sxw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b="V/85NRHC"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id hq6-20020a1709073f0600b007adf3ed5d20si1902465ejc.376.2022.11.17.15.15.01; Thu, 17 Nov 2022 15:15:40 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b="V/85NRHC"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240096AbiKQWuW (ORCPT + 92 others); Thu, 17 Nov 2022 17:50:22 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47542 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240499AbiKQWuK (ORCPT ); Thu, 17 Nov 2022 17:50:10 -0500 Received: from mail-yw1-x1134.google.com (mail-yw1-x1134.google.com [IPv6:2607:f8b0:4864:20::1134]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E641665E76 for ; Thu, 17 Nov 2022 14:50:08 -0800 (PST) Received: by mail-yw1-x1134.google.com with SMTP id 00721157ae682-39451671bdfso8165567b3.10 for ; Thu, 17 Nov 2022 14:50:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=oBQqoT8aYHZ0vQjXNPjZ+F7M4m+OJwx56OthzoHvy+Y=; b=V/85NRHCgCKO6025dTcmKElFHjJs4o4UrvwFg35hm1KxroNrAGF7AQPOo4PAFFpz/1 FS3VuVIVF/5YlLLk0sxnl4d97EI1auCMb5+574cvZaCuSN5BiDDIMzJ6YGQGg7mF2+AT M4KFp0JqJK0f2A6W27QB6t3TmXruVIwmPoY6t8nvHesVZl7BojEroj9PPAxBg/etlutO XyP6d641aLZ4M1/nneKxVrm1aavnuQb6odm5omN3sW9OazWK1It2axj5S9sME0fNfi9B aYQ7+zQout9E3QFu4beIntb8LQKs7LmaTBsgg6fZLaPifO/rIvTa+ngGvAVnY5snL4LZ BVIQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=oBQqoT8aYHZ0vQjXNPjZ+F7M4m+OJwx56OthzoHvy+Y=; b=dhUr4CSMMsBRtDotz8jLZTn2zVQjVpPJqMWDNzBZ/e9E/3sWLnrTkn8h3ecjDmnN6H tw0BaxStTTTUFlHLN8ADs/vQp8kffzDPd38F7GXh3k45B5nqsuAgtRIeom15WN0GJbTj V8/q5LZiC0Guvo0e7UggGUOo2EupJ9Jbe/J6MOaVAV7sDL61g8IvYUFokwckEfUqWiG2 hYUfuppXmccwAZVtpqD4Sdk8ICSwGapxJ2qu2ssSPfogb8NCMBbV3R97hks9GZ3lqIxv dyTyqFVDMgxXEu84aNMWRR7zMpCf8FaPBhNJrT+KpqCnd9jQEU60A50Wl4WJYPk9zWDT xj3Q== X-Gm-Message-State: ANoB5plxC/bw6249LWHEQVwZUgvXo01nVGKFyPVmpCEFU29CIte90LI0 9fxlO1V40HARx46lj+Pndvsv1NXZGyb3Bg4rHsqOew== X-Received: by 2002:a0d:e601:0:b0:356:d0ed:6a79 with SMTP id p1-20020a0de601000000b00356d0ed6a79mr3999955ywe.489.1668725407806; Thu, 17 Nov 2022 14:50:07 -0800 (PST) MIME-Version: 1.0 References: <202211171422.7A7A7A9@keescook> In-Reply-To: <202211171422.7A7A7A9@keescook> From: Eric Dumazet Date: Thu, 17 Nov 2022 14:49:55 -0800 Message-ID: Subject: Re: Coverity: __sock_gen_cookie(): Error handling issues To: coverity-bot Cc: linux-kernel@vger.kernel.org, Marc Kleine-Budde , Paolo Abeni , Stefano Garzarella , Jakub Kicinski , Nikolay Aleksandrov , "David S. Miller" , Florian Fainelli , netdev@vger.kernel.org, "Gustavo A. R. Silva" , linux-next@vger.kernel.org, linux-hardening@vger.kernel.org Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-17.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, USER_IN_DEF_DKIM_WL,USER_IN_DEF_SPF_WL autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Nov 17, 2022 at 2:22 PM coverity-bot wrote: > > Hello! > > This is an experimental semi-automated report about issues detected by > Coverity from a scan of next-20221117 as part of the linux-next scan project: > https://scan.coverity.com/projects/linux-next-weekly-scan > > You're getting this email because you were associated with the identified > lines of code (noted below) that were touched by commits: > > Wed Nov 16 12:42:01 2022 +0000 > 4ebf802cf1c6 ("net: __sock_gen_cookie() cleanup") > > Coverity reported the following: > > *** CID 1527347: Error handling issues (CHECKED_RETURN) > net/core/sock_diag.c:33 in __sock_gen_cookie() > 27 { > 28 u64 res = atomic64_read(&sk->sk_cookie); > 29 > 30 if (!res) { > 31 u64 new = gen_cookie_next(&sock_cookie); > 32 > vvv CID 1527347: Error handling issues (CHECKED_RETURN) > vvv Calling "atomic64_try_cmpxchg" without checking return value (as is done elsewhere 8 out of 9 times). > 33 atomic64_try_cmpxchg(&sk->sk_cookie, &res, new); Hmmm. for some reason I thought @res was always updated... A fix would be to read sk->sk_cookie, but I guess your tool will still complain we do not care of atomic64_try_cmpxchg() return value ? diff --git a/net/core/sock_diag.c b/net/core/sock_diag.c index b11593cae5a09b15a10d6ba35bccc22263cb8fc8..58efb9c1c8dd4f8e5a3009a0176e1b96487daaff 100644 --- a/net/core/sock_diag.c +++ b/net/core/sock_diag.c @@ -31,6 +31,10 @@ u64 __sock_gen_cookie(struct sock *sk) u64 new = gen_cookie_next(&sock_cookie); atomic64_try_cmpxchg(&sk->sk_cookie, &res, new); + /* Another cpu/thread might have won the race, + * reload the final value. + */ + res = atomic64_read(&sk->sk_cookie); } return res; }