Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp2833536rwb; Thu, 17 Nov 2022 17:15:01 -0800 (PST) X-Google-Smtp-Source: AA0mqf5c6/+eL9c8RemZP4duHWOihQa7Dgbffm6LW1GQHhtqTWmrdTb5QScred92qz7rAMDdobLu X-Received: by 2002:aa7:8d06:0:b0:56d:570a:ef1c with SMTP id j6-20020aa78d06000000b0056d570aef1cmr5431015pfe.22.1668734100915; Thu, 17 Nov 2022 17:15:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668734100; cv=none; d=google.com; s=arc-20160816; b=dABJr2NmD3zexRGdt0FguEpFfHV+6d6Gm0EH+d7+o7LisfJFmm2S4P+gWDmjjKZHvT AA0UN8a85CdP2F1WmHSyuV6ZlX7C3iqi+A0OpVat9Bgp5Dp5+t1PX4sjy7g+aq2sRtCt R56XsDgsFrsUI80580NqLv9TcQmJHxE/9P2JBGbkIg+0NThj5GO96+W9EB5H6RQeOwYl Alf/B8dKgHSvrguCA18EUiOukyISaiveQG2UCSjocdMo1qDwf5LBxFJMGIJuVZWJcNTE 6euJwcABAA5Oz+aJGcHuaP3y+qxZ9iZN8as9sWeJqrNkwUEltW/NrDgYGfQ8Bj6W29lh Mxdw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=W25mprsVAGFYx1b8fr8tlqYACFsmAXWC018XR5v0SyQ=; b=dMfaSVdHW3v/dXpcPqtFJuwOsVcNV5HKpk6YODzyMM0BMBc21xkL55NPd6GNaM0OxP Fmlu4GP/Z9HeKELnxa4IYULpUx1pL/BTEZp8jiJ+pmqRmZvFK6pccHvGJC9HFo/0lcjL uq1imhXoxc9a6VaunVbFgmT1XWNWba+S0hQ6BcorzXm+xzkB2KfwR4eIpl28VN6kquIi iFqIpGgMemW2wrHZoU9ymnG1eb5n3RHlRIbkIoVLf5D4l6Gb9atXNYs99b67NjNzQpgU D9xasyjxiV1dxQe8qVnfzmpDpC8TgXb5Wk/oqtTA9bnjhEHdoZIZ+ADm56YiJksVDEPJ XQBw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=XgVP9ahb; 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=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id q6-20020a6557c6000000b0045ff2a2f569si2467378pgr.808.2022.11.17.17.14.40; Thu, 17 Nov 2022 17:15:00 -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=@chromium.org header.s=google header.b=XgVP9ahb; 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=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234955AbiKRAZe (ORCPT + 91 others); Thu, 17 Nov 2022 19:25:34 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38660 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234747AbiKRAZc (ORCPT ); Thu, 17 Nov 2022 19:25:32 -0500 Received: from mail-pf1-x433.google.com (mail-pf1-x433.google.com [IPv6:2607:f8b0:4864:20::433]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 45A6D6B3BE for ; Thu, 17 Nov 2022 16:25:31 -0800 (PST) Received: by mail-pf1-x433.google.com with SMTP id v28so3351082pfi.12 for ; Thu, 17 Nov 2022 16:25:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=W25mprsVAGFYx1b8fr8tlqYACFsmAXWC018XR5v0SyQ=; b=XgVP9ahbj6EU5vSIAnUUS1ZmD8OtEcB/doWcaMRGDvy0kCsATAovnYDAFIryGlxpSh BjxXnEkc4++35Ihn95RQ6EMsvQgfMvwIZWxKDq5QOlnuP3LN9W/41z+o1A/qrq6ygJzS 9D1QCl/mw4vifIZw8zDQnA+7imicunjdy+ddo= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=W25mprsVAGFYx1b8fr8tlqYACFsmAXWC018XR5v0SyQ=; b=VO8ETtGWj98EoO0JK8AN3k7itkOi5nPoegw5W9swL1XMiaeadJ/21esSRmwfC3skam +p5sWLImNOuvsbp7KLSLzrxtcLlysm5tJ4+AzuU5EHcjj4+9iit7F/KpGCqrxgUw3scb u4QAzeRpuH2u6LQ8uLvVqcgzTu8WFTUzVZZlTrp5s7AdQxfyyS3+WFVGA4KzQO/hmtrX F6+UDQiU8mB+0Wce4VR2u53pjAFL1dyLfYLDzFAMEdImU7fLmwfqh4XfWIqjVr4n1tte hmDSQU2xMYoLCP75BaMNaAUQwrSrmpcfPTv41+B5swPeTFZLh/19szqbAT0p+qZeSMcI 6mnw== X-Gm-Message-State: ANoB5pm3cwmgtUB2yFV79W7bZXaU3y4RalUYQgKh4Vs7C9Qj6MwSOjyI vKRZ3cLPPI5ps5xvaplTMB6VVQ== X-Received: by 2002:a63:b54:0:b0:434:911a:301 with SMTP id a20-20020a630b54000000b00434911a0301mr4569707pgl.50.1668731130811; Thu, 17 Nov 2022 16:25:30 -0800 (PST) Received: from www.outflux.net (198-0-35-241-static.hfc.comcastbusiness.net. [198.0.35.241]) by smtp.gmail.com with ESMTPSA id mt15-20020a17090b230f00b00212d9a06edcsm870576pjb.42.2022.11.17.16.25.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Nov 2022 16:25:30 -0800 (PST) Date: Thu, 17 Nov 2022 16:25:29 -0800 From: Kees Cook To: Eric Dumazet 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 Subject: Re: Coverity: __sock_gen_cookie(): Error handling issues Message-ID: <202211171624.963F44FCE@keescook> References: <202211171422.7A7A7A9@keescook> <202211171513.28D070E@keescook> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS 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 03:22:22PM -0800, Eric Dumazet wrote: > 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. Ah! Okay, now I understand the added comment. Thanks :) -- Kees Cook