Received: by 2002:a05:6a10:1d13:0:0:0:0 with SMTP id pp19csp2004080pxb; Sat, 28 Aug 2021 01:24:58 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzpJRhQAfTfiCncSKsH/u0rw82TtGA9yrjqkJoZv64xJNNFnnax/cb4560SjnYJIUOQPlr/ X-Received: by 2002:a02:294b:: with SMTP id p72mr12157977jap.0.1630139098136; Sat, 28 Aug 2021 01:24:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1630139098; cv=none; d=google.com; s=arc-20160816; b=TdmYiWM6DH2QneYRH8ZvVvmEG1dX9MomIyj/SagwnVcQzBRYyQ/azDjzUp0X+h47g+ 9HgmfX6kTi9k23fJXGZa6iJSPAP7edou6ZTw4BApv0Joh63t0KBgLu4LStdpLognVL6K Hcci4J62oJfa37h1jFJXBfOETklo07B47SV3tpSLwPBWdnCbRTRPwUiqEb9ay6PdvCMy gPUL++Li4Uhu4L+5W+ZdnNHlX07QebvKXMKaIKnCTfRBy4YzUFD41CnALUkSbwChglgB 6Qy8td2/L79DeMLjRHHI6TzVeBJCePl6z32P0CaKcQ++mGhebXGO/1WRlPUI2fZUBuNW BXWg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:to:subject:message-id :date:from:in-reply-to:references:mime-version:dkim-signature; bh=SyxSTDORI/8M4AERtcsdRdIUyJ2TeIzi/T8dD70iLxQ=; b=NdyOaLIl2c3azNfR0ls0D8ebdidQjK8C/oKht7Aukkewjdfu4d78pPgvm0vKR4iaif DCbAdabIbsdzxhXsDwgVCxB4tdZokPUj+6xW0Q2exaNX1h6FtCGDFMsyDyS0rxIbw1fl +HhIguxMZYshKG4g3H+9gsmDcW6blzKwn3faX/oljnmg9v71/vj3+ZgXzA+amVr0fsvV fL7+4rr42sDnGaQYDcpa+xnPOGTRfF/1nY416cFf6o04SIUjop0ZHhFTV6pUkxxGuMy9 8NzpRV/BwvIzFDMh35R8OG9af83FqHKrcIoVOPIXQkkIh+wFgLpbj1uzajSlxrNCKpzN 54jg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=j2PQOEMx; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id y21si9150245jat.7.2021.08.28.01.24.46; Sat, 28 Aug 2021 01:24:58 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=j2PQOEMx; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233424AbhH1IY4 (ORCPT + 99 others); Sat, 28 Aug 2021 04:24:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35792 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230208AbhH1IY4 (ORCPT ); Sat, 28 Aug 2021 04:24:56 -0400 Received: from mail-lj1-x230.google.com (mail-lj1-x230.google.com [IPv6:2a00:1450:4864:20::230]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 10DA1C0613D9 for ; Sat, 28 Aug 2021 01:24:06 -0700 (PDT) Received: by mail-lj1-x230.google.com with SMTP id f2so15895993ljn.1 for ; Sat, 28 Aug 2021 01:24:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :content-transfer-encoding; bh=SyxSTDORI/8M4AERtcsdRdIUyJ2TeIzi/T8dD70iLxQ=; b=j2PQOEMxcHXxsJe18inN4YfzVn+rH0fKwUv/j3RPljlPoNikkKagHxgU3UPVOWHucb N63V3cz6yu5BShYtJFn9jcWF3nS3jPa3wJybPrUosAiBhpUi3AinmhQ9CxmfuWx5fQul P1Daz5iR7uUS+EGlyOoiV8Cb38+s0Kb654WnUgcUwNL55EAU1i1zlA8Qsn33Kbm6M24u YYgSLft5yoJmIqB7n7aHU3ErPWOaFRhGW8NjWm81dZSKxZW5C/JcFDRCpZh4UdyA6/8i 8EZsXJPFcpsEBENRV+FUzkL/Gr8V4eUAmGse5qsKCaXHXMVQkGYMSuN24fggmu/soVpL qxmQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:content-transfer-encoding; bh=SyxSTDORI/8M4AERtcsdRdIUyJ2TeIzi/T8dD70iLxQ=; b=U0F7n0FV25li4e0RlsrQBakdVN6GjppDIm6OxQRQBkI39kC+VjC9rP15VbdFXva9Wy P5XGMKxHqlVUbBB1gF1MmIXhxZUg2wYW+QM1nIIh6crnQG/LguSTOYf959404WE6AgfC YfbALF7Dxmfbtcn/et8KAwLU+GzlR/pKRs2Vh+UGrCXma7FrFeNoFxjS+BpUbe7UFFiH R8rWSi9JzMjnFZXinrKw7WVL7ymxkjwxOXSR0KQ0iJakwW8zi3n9awOy8NKBvEve5rzb Nw8K2DVMFB3UNEle3bLDwsPnZR94dIowOJcdQ/CyjnwR+Rp565zqbeFYm7WX0iosIefI 1GlQ== X-Gm-Message-State: AOAM530DrTg6he3V5ljN6Tysa98D6cPkZdDRJszreciOpRI4TD492nN3 6KO7mbZzXgfz8wn7Ub7h/PFAo0OoJzKP99/oaNvIbXVe8ECDRg== X-Received: by 2002:a05:651c:510:: with SMTP id o16mr11337086ljp.257.1630139044155; Sat, 28 Aug 2021 01:24:04 -0700 (PDT) MIME-Version: 1.0 References: <20210801090830.GB18001@1wt.eu> <091e487a-d458-45d4-613d-b25ca7bfc98c@fb.com> In-Reply-To: <091e487a-d458-45d4-613d-b25ca7bfc98c@fb.com> From: =?UTF-8?B?5Y+25r6E6ZSL?= Date: Sat, 28 Aug 2021 16:23:53 +0800 Message-ID: Subject: Re: Protential deadlock in linux/tools/testing/selftests/bpf/prog_tests/sockopt_inherit.c To: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Yonghong Song =E4=BA=8E2021=E5=B9=B48=E6=9C=882=E6=97=A5=E5=91= =A8=E4=B8=80 =E4=B8=8A=E5=8D=8810:56=E5=86=99=E9=81=93=EF=BC=9A > > > > On 8/1/21 2:08 AM, Willy Tarreau wrote: > > Hello, > > > > On Sun, Aug 01, 2021 at 04:56:37PM +0800, ??? wrote: > >> Dear Maintainers, > >> > >> > >> [image: image.png] > >> This code snippet seems to be problematic since it may cause a deadloc= k > >> problem. > >> > >> Description: > >> When *pthread_create* in line 197 fails, *server_started_mtx* will not= be > >> released. If this function is invoked again then, the executing thread= will > >> stuck in line 196 for requiring an already locked mutex, which causes = a > >> deadlock problem. > >> > >> Fix suggestions: > >> Unlock *server_started_mtx *before goto close_server_fd at line 199. > >> > >> CWE ID: > >> CWE-667: Improper Locking > >> > >> Source code address: > >> https://github.com/torvalds/linux/blob/5bfc75d92efd494db37f5c4c173d363= 9d4772966/tools/testing/selftests/bpf/prog_tests/sockopt_inherit.c#L199 > > > > Sorry, but how is this in any way related to security, given that it's = in > > self-tests programs running in userland ? In the worst case, a develope= r > > will experience a failure during tests where there should not be. Bette= r > > report this directly to the code's authors, without involving the secur= ity > > team. Even better, please provide a patch to fix this. > > Yes, this is bpf selftest bug. The fix should be straightforward as > described in the above. > > --- a/tools/testing/selftests/bpf/prog_tests/sockopt_inherit.c > +++ b/tools/testing/selftests/bpf/prog_tests/sockopt_inherit.c > @@ -195,8 +195,10 @@ static void run_test(int cgroup_fd) > > pthread_mutex_lock(&server_started_mtx); > if (CHECK_FAIL(pthread_create(&tid, NULL, server_thread, > - (void *)&server_fd))) > + (void *)&server_fd))) { > + pthread_mutex_unlock(&server_started_mtx); > goto close_server_fd; > + } > pthread_cond_wait(&server_started, &server_started_mtx); > pthread_mutex_unlock(&server_started_mtx); > > Agree with Willy, maybe you or somebody can provide a patch to fix the bu= g? > > > > > Regards, > > Willy > >