Received: by 2002:a5d:9c59:0:0:0:0:0 with SMTP id 25csp94161iof; Sun, 5 Jun 2022 22:10:27 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyuMiNYd2plJvPfZ2a/dagOet42Wqgzj0P+XXW4eRHHcvMKbG6YquGVvYTM2KhhaALrCAv1 X-Received: by 2002:a17:90b:4c85:b0:1e5:42ef:a921 with SMTP id my5-20020a17090b4c8500b001e542efa921mr27888153pjb.75.1654492227522; Sun, 05 Jun 2022 22:10:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654492227; cv=none; d=google.com; s=arc-20160816; b=tTfwD3pypz/MsyNhSvm+MqH44oNWhl0wK4bhUgWf99Xnpzj0sRJIYlq0bfdfhPehdy +OQVNcUrL1Z6HRl1u5Py4iSWm1vSrKgR8MDYFBNCW83ghS/twwkOu0GQ/GlWSKQxJvtn R5G12WiuUrJNwgZRh2xe98064jWZQfkXQz6nbVogRcKWRMUVpEqDoGBnc0ofLPEutb8a OOczXoIplYaga5/35Q0sZMgkCqgZvlcHOQxBHXQJUJNPzJo+wwGNwKo2akp6hoW5amDB 1jSuBKJv99B+sVuZW/+vBqkYzDt1+VEWPIuw0QbiJ43ldelKo8lel+AlQjrILidwErdU UCoQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id:dkim-signature; bh=Az2acnj16/aXPRCs4OX6YtuTWRNeGltXq9+PbmTT2go=; b=vwmcB8FyE4gvw00qwJgtIbDDNwNNMe+gyhxKNWxwwaMMOMyQnjdXltCN9i0ZqORk9V lz+h4k3TZqrqdeZqrA0qmZaEIpu2KnACEgijkXzOCJDxYkwigRqp0sSz6Ft6QobQcBjI SjVAulHJoQBAQ1ki0xYQ5Vv0sL0v5WBRUxbsT8W6c+4idXZ3Yex0CxsJe2Pi76moosXW 5BrxmDCFGfPfzgPk3R9k65/htpfJphbyPwuzCHxhVsJwrL705DQulSKm849c1GbIyiGZ BYJ0xkkZCG/+K1dLJTWOX8DIOnjfULG1izijwlpxE9ANFyOPeyGawEci9kPQ1/tCKAU2 xeDw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=P+Blsdx7; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id y191-20020a638ac8000000b003c15242c486si19397866pgd.787.2022.06.05.22.10.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 05 Jun 2022 22:10:27 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=P+Blsdx7; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 66A2D13F1DD; Sun, 5 Jun 2022 21:17:28 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346935AbiFCSbh (ORCPT + 99 others); Fri, 3 Jun 2022 14:31:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46544 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347293AbiFCSbW (ORCPT ); Fri, 3 Jun 2022 14:31:22 -0400 Received: from mail-pl1-x630.google.com (mail-pl1-x630.google.com [IPv6:2607:f8b0:4864:20::630]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E20FE193F6 for ; Fri, 3 Jun 2022 11:17:25 -0700 (PDT) Received: by mail-pl1-x630.google.com with SMTP id i1so7361422plg.7 for ; Fri, 03 Jun 2022 11:17:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=message-id:date:mime-version:user-agent:subject:content-language:to :cc:references:from:in-reply-to:content-transfer-encoding; bh=Az2acnj16/aXPRCs4OX6YtuTWRNeGltXq9+PbmTT2go=; b=P+Blsdx7NzfX+tc3SEE3y7hR4zxwbKm4W2XIzjhNeSBoA+J3idLz4PKuU0Rgg4bqeT 8lBP2muYp3hJexMlCEEKRnfjA8kkU7Ktpm+ktqsZzLj/Bps9oNU5lakmUmkSzZZvJbIw 0qVv48vpCqMPKK6//GckvorWP4FKNyXfKRdKBPD2dx7i7608+Pyv7jcbzu4PhcIU7dL9 jJ9Mhm1GemcsDHTmQh64GVr7Yiv0UXLF3ltn2JxNuZClpwltYgmNH6Wk0P7s3/watLWM 9ucceQ8xk1cXq4I+OjOirraMAlWREjNJ1kYf8gOJHA86ZxrD0DrXqxCLe5WOy7pXbakk CQsA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:date:mime-version:user-agent:subject :content-language:to:cc:references:from:in-reply-to :content-transfer-encoding; bh=Az2acnj16/aXPRCs4OX6YtuTWRNeGltXq9+PbmTT2go=; b=dq5oPYEnMMAuMOF0HBeCJKtDj8sbPUlZJ3F58x9rYHVkMVadnoDRhVW33b/vzJVIK7 ut4ntgrmNO3OdBnjxMSdh4uXavcDr+aznyym9zHoMQ4PbuMNV58O0BTmYg6Rs9aQlbSb iV+f4VYwijf5Wh14ZYN0FPGsQ68sc47HFH+Y7m9mDIhj9iiKnJZ/Mi8ZuoQK5kkOgd9A R7m3udj9TRb4vTiDpiX7SpIxfxOBwJbe3A877uV+NrNBs1K/O4eWeKMqfQxUDNowgRac Dk1jJRLShMr3IXAWoOSxo/Z4RIQmlNWGQ97kAmyJdudDq4i8eUkxdbCRGvyTJeU/uQD+ /kWw== X-Gm-Message-State: AOAM532dpF76aohMh1Ynn+eLgeaXq5flIKvAmXHvQJXMMTWiq7Zz1Ysu BlePF7nlOaXxC4Oxjn1B+9x2sQ== X-Received: by 2002:a17:90b:1646:b0:1e3:15ef:2871 with SMTP id il6-20020a17090b164600b001e315ef2871mr27004228pjb.105.1654280244917; Fri, 03 Jun 2022 11:17:24 -0700 (PDT) Received: from [192.168.254.36] ([50.39.160.154]) by smtp.gmail.com with ESMTPSA id bx9-20020a17090af48900b001e270cc443dsm7965713pjb.46.2022.06.03.11.17.23 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 03 Jun 2022 11:17:24 -0700 (PDT) Message-ID: <0c37c2b9-a89a-54d7-9fd3-f035f6816aa8@linaro.org> Date: Fri, 3 Jun 2022 11:17:23 -0700 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.10.0 Subject: Re: [PATCH v2] cgroup: serialize css kill and release paths Content-Language: en-US To: Tejun Heo Cc: Michal Koutny , Zefan Li , Johannes Weiner , Christian Brauner , Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh , cgroups@vger.kernel.org, netdev@vger.kernel.org, bpf@vger.kernel.org, stable@vger.kernel.org, linux-kernel@vger.kernel.org, syzbot+e42ae441c3b10acf9e9d@syzkaller.appspotmail.com References: <20220603173455.441537-1-tadeusz.struk@linaro.org> <20220603181321.443716-1-tadeusz.struk@linaro.org> From: Tadeusz Struk In-Reply-To: <20220603181321.443716-1-tadeusz.struk@linaro.org> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-3.2 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,NICE_REPLY_A,RDNS_NONE,SPF_HELO_NONE, T_SCC_BODY_TEXT_LINE 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 6/3/22 11:13, Tadeusz Struk wrote: > Syzbot found a corrupted list bug scenario that can be triggered from > cgroup_subtree_control_write(cgrp). The reproduces writes to > cgroup.subtree_control file, which invokes: > cgroup_apply_control_enable()->css_create()->css_populate_dir(), which > then fails with a fault injected -ENOMEM. > In such scenario the css_killed_work_fn will be en-queued via > cgroup_apply_control_disable(cgrp)->kill_css(css), and bail out to > cgroup_kn_unlock(). Then cgroup_kn_unlock() will call: > cgroup_put(cgrp)->css_put(&cgrp->self), which will try to enqueue > css_release_work_fn for the same css instance, causing a list_add > corruption bug, as can be seen in the syzkaller report [1]. > > Fix this by synchronizing the css ref_kill and css_release jobs. > css_release() function will check if the css_killed_work_fn() has been > scheduled for the css and only en-queue the css_release_work_fn() > if css_killed_work_fn wasn't already en-queued. Otherwise css_release() will > set the CSS_REL_LATER flag for that css. This will cause the > css_release_work_fn() work to be executed after css_killed_work_fn() is finished. > > Two scc flags have been introduced to implement this serialization mechanizm: > > * CSS_KILL_ENQED, which will be set when css_killed_work_fn() is en-queued, and > * CSS_REL_LATER, which, if set, will cause the css_release_work_fn() to be > scheduled after the css_killed_work_fn is finished. > > There is also a new lock, which will protect the integrity of the css flags. > > [1] https://syzkaller.appspot.com/bug?id=e26e54d6eac9d9fb50b221ec3e4627b327465dbd This also fixes a similar, cgroup related list corrupt issue: https://syzkaller.appspot.com/bug?id=3c7ff113ccb695e839b859da3fc481c36eb1cfd5 -- Thanks, Tadeusz