Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp2784170rwb; Thu, 17 Nov 2022 16:20:47 -0800 (PST) X-Google-Smtp-Source: AA0mqf6spDnp3/ykHhYuiJsChELuBZwTxAo+G/PzocbmMwi4kPo9NFE+MasNci8YPo05XUv77TKp X-Received: by 2002:a63:5d62:0:b0:477:2263:a5d with SMTP id o34-20020a635d62000000b0047722630a5dmr1840581pgm.536.1668730847145; Thu, 17 Nov 2022 16:20:47 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668730847; cv=none; d=google.com; s=arc-20160816; b=RS6BHBa87R8ay7EWy0NhkwEJ2Y2p+2DOuz3/6Hvl6MN8gfMWqJE+1nFE5y510ceDzv 2KCVCCYPhrMguLbs9XiWR8PYUr2ANVX1HUdsBoEaJqGTlebP3aBxqwLd1H4kj2I9UTCT E/A0k5/q/lrBPk5l7LMWnZIhBOKc4RAst3wRM3colAm6ASjeWq+QpywrLVYEqfQBEWOw hLyJvImHWRn8b8JVEU6Zt1s+ytEFHhcrD2bJGIULEM87GwIcM2qqtMkfPX2rkD2iBdmV bIWkpTGaZCmlxTz0rxiipKpnt+g39V0KxIVsD0kPTryQGVSqqfZoKS+cPd9Y+Wd0K1pf lEdQ== 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=FXOYABrnPgmp9jzsBlpFNkATp6bu50ERFKeMiB3FwT4=; b=N14dX7g+aucaOTdakAmPSHIhK3Aa4tCnpBXw2Kwr1IYjXar1iGKjmm2Xv3c/vxSQZZ ST3ILD9F/fxbAGiWbv8lFSyZgsNLfjSST5EuSprfVUf3KU35l9NJTu9LCFnpIGBmN40e 6aY3YTbHbkqd1H1g9lOzR9SghkTKIQ/8Su+CnEzln3tZ7Rag2Ej7fIxlo4XZ8cxs/3Yz VuOA0JGW9e6WD2f8GlFxLC5a6aYM3uR+5EabMf4Ar2Dh5b0E8efDOoGygJUpxnC4CvPj P58Lzi7YfT8daqAnf/fN+Ks51xAqfkyuCSd7Fv9Qky5YS6yD74VoqBWbCZkAPFCUebly J55w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b="cBRkXp7/"; 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 pi19-20020a17090b1e5300b0020aeaa98ed4si6647104pjb.93.2022.11.17.16.20.35; Thu, 17 Nov 2022 16:20:47 -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="cBRkXp7/"; 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 S239771AbiKQXWg (ORCPT + 91 others); Thu, 17 Nov 2022 18:22:36 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37466 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235128AbiKQXWf (ORCPT ); Thu, 17 Nov 2022 18:22:35 -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 3D30372985 for ; Thu, 17 Nov 2022 15:22:34 -0800 (PST) Received: by mail-yw1-x1134.google.com with SMTP id 00721157ae682-3876f88d320so34102307b3.6 for ; Thu, 17 Nov 2022 15:22:34 -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=FXOYABrnPgmp9jzsBlpFNkATp6bu50ERFKeMiB3FwT4=; b=cBRkXp7/oBqBkFbBArBcjw6enjHfL3c5C4se/3b2EPPjNVaVcxDZ0nzxv0kZHvxHhK vA1Njoe6VFnuU06abq5ovlF3Azi6Z6+/NnUKwobpSxrorCdSUxeo/Z0z9ElCO+1oa7Xn rJHLLYVChnAOgRCTrvozFEuYt60shSGQJYpEeG7eC4JETCS6jJjtAJhnYZn50q1IJBP9 xrEnqwRFweRpk5zLkKozTeIeE6ACpCWbmSUR2gqAlrEnGn7AzOddW5c7NycrLYlVAK3t jPPFmM8a4ZRkWuMc42/AtZ78qZW5KTOIMhsa6YTup/5OR+1scWDa7Ys1lbxJiID8Qa0p Kpdg== 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=FXOYABrnPgmp9jzsBlpFNkATp6bu50ERFKeMiB3FwT4=; b=5begJ3nouAKpn0a2B5EvKKwzH4sXLeZwt89oLsV+fBYllszHVkWfplL6jZOT9BcCpz CzCALpODJc0895voyTqiZk+Ep4xjoejWMwkzJArLA3CqjddRXGm8vz3AaJBZYMhBZXJ4 EMfmqNZX02TirPijZPVD6ypw9jT2DHRYIGjyE3IbYpDzPOfE8vf88uztwqRT2XsfEQNv sFyQfgTVZ8aH/oHn8dsmt8IBTuXfbojvjoihsTiZyASsUJCJAqA5Y7jshKoUlNmAjK+z O56cVXenHr8/gBXLqP5rfonIWqkbFrrNRzJSaOXvqGI2bA8uudhFimjitM/6UOZ1zgDc Kzsw== X-Gm-Message-State: ANoB5pnvnBYEnUT8FPAJwZRDmbLvnI7GrEbqYiS1iobGo+GnFsZXYJ60 EqN20fS/tc2IZ7i5Pq39sm5npqdJxfdjatPe71Pccw== X-Received: by 2002:a05:690c:b0d:b0:377:6947:a6b4 with SMTP id cj13-20020a05690c0b0d00b003776947a6b4mr4013023ywb.332.1668727353234; Thu, 17 Nov 2022 15:22:33 -0800 (PST) MIME-Version: 1.0 References: <202211171422.7A7A7A9@keescook> <202211171513.28D070E@keescook> In-Reply-To: <202211171513.28D070E@keescook> From: Eric Dumazet Date: Thu, 17 Nov 2022 15:22:22 -0800 Message-ID: Subject: Re: Coverity: __sock_gen_cookie(): Error handling issues To: Kees Cook 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 3:14 PM Kees Cook wrote: > > On Thu, Nov 17, 2022 at 02:49:55PM -0800, Eric Dumazet wrote: > > 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; > > } > > I think it's saying it was expecting an update loop -- i.e. to make sure > the value actually got swapped (the "try" part...)? The value has been updated, either by us or someone else. We do not particularly care who won the race, since the value is updated once only.