Received: by 2002:a05:6358:5282:b0:b5:90e7:25cb with SMTP id g2csp3246888rwa; Tue, 23 Aug 2022 01:05:15 -0700 (PDT) X-Google-Smtp-Source: AA6agR4H9VEgKwJfPfKIppi8SOOw5pmShPDVJbBgCAmxz0ULGRI/smN4+ZP2n1+PS0cl6RUkUWUK X-Received: by 2002:a17:90b:3c44:b0:1fb:30ae:95c2 with SMTP id pm4-20020a17090b3c4400b001fb30ae95c2mr2158711pjb.215.1661241915063; Tue, 23 Aug 2022 01:05:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661241915; cv=none; d=google.com; s=arc-20160816; b=SUhTrUH1oHYG3lK1Oe0Hk3bztq/LH2ezG6VwyZng5/6MdtHnFIDvaD5582EVxbwiZb msjLKK4sr5hTw28OZy7ipfISTgesww67dbjqziGd7+OVYTT1Q7vT5XHDADBOi0CiLlxS IB8CSimcRBHhWlV+spRZprExCCzvxfD9AhFazF0HITEK2BY2sUqKCeRR3OyyN/tTzRkq luJZz0a2ckpm/sJsytigMyQ1twjHRRolDlEgKw0NHkghr9/fH1odnBg5bChQfMiCfnBH lVWA1sYKqNZRSzzmy2LUEoEHqekX5Od5hf/8QYPOo4kUUP6Lg4ldxC9i290gmJb9tA6B /Edw== 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=ByV0BJNHZqTpDV2aCXhNaq+ajDJSBBoKun5SDdoNVjM=; b=Zzhk/Q0aBWnvdTnRFEyMimJVRiqpHxX6mO5A+kh+aE2HUvOABblavy/BUpnkft32m/ h6f6+vTq8G7xhbNwuuxiv5/0IuxuKOsUVhysVwNNq6DIo6DOfxZV0GCliCmInoo2jZUm /lhww39XGap6N+BrejycHyuiHP9tGNpe1VBshJiIOnNl1fbhTIn8zsLlscn4mC5TRd9G XwqhR48Ky1zbG6J0kgJTkySfpMvepqjpRZ71lnX6j4tGVsNVyFN4HBEBObOdSOf84y5W yXsEmjFVFCYhE7/PC45KNrCnhss8HAfDiQMKtx/ew8UgUYxY/nLl2g9ys8zkDcECVRr5 /UAA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="pjTr/Z6S"; 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=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id s189-20020a6377c6000000b0042ad3e1092asi2767837pgc.226.2022.08.23.01.05.03; Tue, 23 Aug 2022 01:05:15 -0700 (PDT) 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=@linuxfoundation.org header.s=korg header.b="pjTr/Z6S"; 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=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240708AbiHWHZk (ORCPT + 99 others); Tue, 23 Aug 2022 03:25:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58802 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233020AbiHWHZi (ORCPT ); Tue, 23 Aug 2022 03:25:38 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 773FE62A93; Tue, 23 Aug 2022 00:25:37 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 289A0B81BDB; Tue, 23 Aug 2022 07:25:36 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6A338C433D6; Tue, 23 Aug 2022 07:25:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1661239534; bh=58Xb+4i5V/oco9O7BavXUkLRRYHB+58DLbXicNZDwh4=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=pjTr/Z6SvB4TmFzMxTfi4ZLz2yva0Pmx+Rx4GcRvdiO3jgYYYfnFpQxYAU9ieczXX uNjwd8sTRcPzn35myL47BwZ5xGyR1WQXMS9eyUrUQZVFA6/+6LmKYr4oZ50Ex+AvTd RresWZXixK4Wa+E2pudBmcywk+jdu6j/UYacXUSk= Date: Tue, 23 Aug 2022 09:25:31 +0200 From: Greg Kroah-Hartman To: Pu Lehui Cc: bpf@vger.kernel.org, linux-kernel@vger.kernel.org, stable@vger.kernel.org, syzbot+f264bffdfbd5614f3bb2@syzkaller.appspotmail.com, Andrii Nakryiko , Tadeusz Struk Subject: Re: [PATCH 5.10] bpf: Fix KASAN use-after-free Read in compute_effective_progs Message-ID: References: <20220820050518.2118130-1-pulehui@huawei.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220820050518.2118130-1-pulehui@huawei.com> X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham 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 Sat, Aug 20, 2022 at 01:05:18PM +0800, Pu Lehui wrote: > From: Tadeusz Struk > > commit 4c46091ee985ae84c60c5e95055d779fcd291d87 upstream. > > Syzbot found a Use After Free bug in compute_effective_progs(). > The reproducer creates a number of BPF links, and causes a fault > injected alloc to fail, while calling bpf_link_detach on them. > Link detach triggers the link to be freed by bpf_link_free(), > which calls __cgroup_bpf_detach() and update_effective_progs(). > If the memory allocation in this function fails, the function restores > the pointer to the bpf_cgroup_link on the cgroup list, but the memory > gets freed just after it returns. After this, every subsequent call to > update_effective_progs() causes this already deallocated pointer to be > dereferenced in prog_list_length(), and triggers KASAN UAF error. > > To fix this issue don't preserve the pointer to the prog or link in the > list, but remove it and replace it with a dummy prog without shrinking > the table. The subsequent call to __cgroup_bpf_detach() or > __cgroup_bpf_detach() will correct it. > > Fixes: af6eea57437a ("bpf: Implement bpf_link-based cgroup BPF program attachment") > Reported-by: > Signed-off-by: Tadeusz Struk > Signed-off-by: Andrii Nakryiko > Cc: > Link: https://syzkaller.appspot.com/bug?id=8ebf179a95c2a2670f7cf1ba62429ec044369db4 > Link: https://lore.kernel.org/bpf/20220517180420.87954-1-tadeusz.struk@linaro.org > Signed-off-by: Pu Lehui > --- > kernel/bpf/cgroup.c | 70 ++++++++++++++++++++++++++++++++++++++------- > 1 file changed, 60 insertions(+), 10 deletions(-) Now queued up, thanks. greg k-h