Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp2759831rwb; Thu, 17 Nov 2022 15:57:58 -0800 (PST) X-Google-Smtp-Source: AA0mqf4ONdOovWALiq4LSg7+Xybi6Z+B126lQrsLL7D1FW6D0l00AnOmTQpyDpiIYsGM0SuLjm6I X-Received: by 2002:a17:90a:b396:b0:218:8379:89a0 with SMTP id e22-20020a17090ab39600b00218837989a0mr1359429pjr.81.1668729478314; Thu, 17 Nov 2022 15:57:58 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668729478; cv=none; d=google.com; s=arc-20160816; b=Y1o3IaIZR48upEkg3ztkL2hXJ4KvjyGaGAwVzD8iHEE+ji2OrHs7Yk0RVqIjGdNdFr tafBBszHw0keRh7aK4xlO0hCaBMIYlOlJ1mMAPdNanvQKHe7QNhuab/oe7VOuPeIypLY byL/BpIKsWbf3m2idI/wfmmi5whDdjABH7BxuQ9nDMdMIwOCcnCfohU2kGN22kslNAuw Xye9mu380PnCbmayzUVrDOXu3UEiPdXoKF/hoAnLcSgz3llddt3oyNgwZOaTRROFOsfa RX0KQ8m5bLfY9EfqDYPCQB031uW4B1e2+CevRPYUbT0V65DX6z8C8VYtGmK2kW/f0LaU AUig== 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=mxh7ZIMAwOf8tQ5bBt1rmaA7jYZVydQJoYO/fiU1FyU=; b=JMkLCLv8lPSf8WaKx9F7QEJb+/i/6pYKXPYU+6DHFGhRuncfdvDLLQwsaUS3D+N2EL l6fpV1aDmQJqooFkZ9OPCiBjDKQ0CPOkgK/jkacKlSOx3qQHSs/bvIydh+Trqmyr96DT oGqTE5jal8RwPyqmnx0Zsg2wxJvOzhi03EVirQ+jaTAG84giRCz1xShOpB4KzbLC3i7k qdC12YhYkubVIy3reFc2iox4685JQzHBsDF/3Jek64PEuSdtfKv1o+vBT0Ldr0WCUoCp 841pVY1ZRRpS6lxzP4+3Y2DrndC71dJDmZDzi6CfQduEfMwIjr8T3XdU9JZHj/X2xza8 Z3uw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=AqrwnZuh; 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 q68-20020a17090a1b4a00b0021320088071si1909366pjq.175.2022.11.17.15.57.22; Thu, 17 Nov 2022 15:57:58 -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=AqrwnZuh; 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 S234961AbiKQXOg (ORCPT + 92 others); Thu, 17 Nov 2022 18:14:36 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:32964 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234885AbiKQXOd (ORCPT ); Thu, 17 Nov 2022 18:14:33 -0500 Received: from mail-pl1-x629.google.com (mail-pl1-x629.google.com [IPv6:2607:f8b0:4864:20::629]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BDB37716D2 for ; Thu, 17 Nov 2022 15:14:32 -0800 (PST) Received: by mail-pl1-x629.google.com with SMTP id b21so3016876plc.9 for ; Thu, 17 Nov 2022 15:14:32 -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=mxh7ZIMAwOf8tQ5bBt1rmaA7jYZVydQJoYO/fiU1FyU=; b=AqrwnZuhFVU0aPbl6IZJR1sckJQiFv7nsHmnRXjrQmyy5Clie241H6/UT49hXOVXfZ TuDtO4NNlWlIE0MYuxvXRt/ed8k/ohuRSDt4AX9HIZ3lo9bIgnjFVyWuwAl1R/0xyAcL MCjNVGLccDlGLaBeO0b4AQ6NlugIF8Ihx3eTc= 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=mxh7ZIMAwOf8tQ5bBt1rmaA7jYZVydQJoYO/fiU1FyU=; b=rp0Ppi+sEuq3mXjIdyBUOJxPTE5CT0PwlosMu0fq3RhsNqh3kEG2LjWVz2om0GPDL3 hdxkPnFPwandyzY3R5w6whG30bS02QtnpnjWkCXl6+SbPKWTyWcyjkM3uOZtTZJchqqO ejR2f2qOs2g0H1RkQoCd8wdM62AywK/WJm0LyivzabIVHYbFYBiBcJ/XEgYVhajiNdo4 CrIbfvvZaEaFpdvyk+9/A8ESJCaar2TRveFjLyIi3M/07sndp41xwslzDjBxbzhWEHKh 1caBdNz/hXyVsNU8Kr2J+tJezbuTUsKPxeUGD145sXZmq4Z/LO/ZCVyhykQbbmC0hF+z RFhw== X-Gm-Message-State: ANoB5plPCVO65aVpQJUfUV7q4vMrIN6Wi1Mk07uuK+y+2f3jKDh/sgJB zXHppPx1e6o3wzMgoniLUGYYjLrOnM3edg== X-Received: by 2002:a17:90a:6904:b0:208:4bfa:51e1 with SMTP id r4-20020a17090a690400b002084bfa51e1mr10606132pjj.228.1668726872280; Thu, 17 Nov 2022 15:14:32 -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 19-20020a621513000000b0056c0b98617esm1744204pfv.0.2022.11.17.15.14.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Nov 2022 15:14:31 -0800 (PST) Date: Thu, 17 Nov 2022 15:14:31 -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: <202211171513.28D070E@keescook> References: <202211171422.7A7A7A9@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 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...)? -- Kees Cook