Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5A58AC43217 for ; Wed, 12 Jan 2022 19:50:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345915AbiALTuZ (ORCPT ); Wed, 12 Jan 2022 14:50:25 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37814 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1357751AbiALTuL (ORCPT ); Wed, 12 Jan 2022 14:50:11 -0500 Received: from mail-yb1-xb2f.google.com (mail-yb1-xb2f.google.com [IPv6:2607:f8b0:4864:20::b2f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9BA47C061751 for ; Wed, 12 Jan 2022 11:50:10 -0800 (PST) Received: by mail-yb1-xb2f.google.com with SMTP id h14so8639956ybe.12 for ; Wed, 12 Jan 2022 11:50:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=jRJqEvb6RaoXDTGIGvfe6D9l0JWX3IBGy+0XrscHKFk=; b=A05wtVt0YhyBSdDPVxnMOaffKavmT2bc7mtYBlQvpXZuCcKdvBu2pQnaPFx3DGatS3 dletqWECy0d2sgn8vA9vLAVgNohXHyzj9Cgqbl79LKWXgG+hE4wDbGAhWFykD9TScLom RAoovIZCddTCKuxzFHyAQtyUFKl1Zj9Pah7k/alWN5AMM8RaorUkk56uf1K/F+4vbrJ1 tVX2xsXqH3CMuhvO/jQ0GHItrhwrslksLTTyVuEJKA47jbtOoEt6Dy2V8InbwuqJee6U RtN4mRaJgakGvKhskjQGCe4cEY3Rn9j04AANjfnBq6vDTcY1WWI2cp4TB0GwIncWQef6 qjjQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=jRJqEvb6RaoXDTGIGvfe6D9l0JWX3IBGy+0XrscHKFk=; b=Ll/NtkWoLFGPy211X8GhYKj1aj2+JCJR+PkTQZ4rXQ0cFRJxX1xavCtXsU7LddOhqt /g3ho2tu7hcWL0+7baEKrYiGW7fZalaQ2Kzt9JAu1hr+ROB15LLV9J0qolWpijjfoWUW eJZgdAAszRYhnMTjrx5u5Xy9ogU+eHWSyzM5RgW0WobQaESwz/ehJY1vABJ2sncl+jF5 /Xd8hg7I4duFh//qv/FpiHdvvsnF+g8nbNDnOFi2pX4JWSTwnj3pZfea5hsoKBMgs4h8 iMsbiQBkFFy68Oc7v8Oiy820439YiMFKPqZmeEOumMcK7fsDh1ik4EWOpg1BG+gQfnS9 Uasw== X-Gm-Message-State: AOAM531Ho4W2yNJezqsg1RdGJYqYZFH/03b3WIOHWyEDVzqoEIOMi1un 336x+U3dvEgXnxquZSsCBfaoPn3xzUI8ZfNWcTSEtg== X-Google-Smtp-Source: ABdhPJx6W0X7kISJhEYdoiY21aNG29fuGIZW3ogzIBP7+xBMxjmD0lYfSi3qgeEmYg4Q7LUKrKFZmmy6/h0/7WJ3H6o= X-Received: by 2002:a25:c245:: with SMTP id s66mr1871016ybf.243.1642017009537; Wed, 12 Jan 2022 11:50:09 -0800 (PST) MIME-Version: 1.0 References: <20220111232309.1786347-1-surenb@google.com> In-Reply-To: From: Suren Baghdasaryan Date: Wed, 12 Jan 2022 11:49:58 -0800 Message-ID: Subject: Re: [PATCH v3 1/1] psi: Fix uaf issue when psi trigger is destroyed while being polled To: Eric Biggers Cc: Matthew Wilcox , Johannes Weiner , Linus Torvalds , Tejun Heo , Zefan Li , Ingo Molnar , Peter Zijlstra , Juri Lelli , Vincent Guittot , Dietmar Eggemann , Steven Rostedt , Benjamin Segall , Mel Gorman , Daniel Bristot de Oliveira , Jonathan Corbet , "open list:DOCUMENTATION" , LKML , cgroups mailinglist , stable , kernel-team , syzbot Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Jan 12, 2022 at 11:06 AM Suren Baghdasaryan wrote: > > On Wed, Jan 12, 2022 at 11:04 AM Eric Biggers wrote: > > > > On Wed, Jan 12, 2022 at 10:53:48AM -0800, Suren Baghdasaryan wrote: > > > On Wed, Jan 12, 2022 at 10:44 AM Eric Biggers wrote: > > > > > > > > On Wed, Jan 12, 2022 at 10:26:08AM -0800, Suren Baghdasaryan wrote: > > > > > On Wed, Jan 12, 2022 at 10:16 AM Matthew Wilcox wrote: > > > > > > > > > > > > On Wed, Jan 12, 2022 at 09:49:00AM -0800, Suren Baghdasaryan wrote: > > > > > > > > This happens with the following config: > > > > > > > > > > > > > > > > CONFIG_CGROUPS=n > > > > > > > > CONFIG_PSI=y > > > > > > > > > > > > > > > > With cgroups disabled these functions are defined as non-static but > > > > > > > > are not defined in the header > > > > > > > > (https://elixir.bootlin.com/linux/latest/source/include/linux/psi.h#L28) > > > > > > > > since the only external user cgroup.c is disabled. The cleanest way to > > > > > > > > fix these I think is by doing smth like this in psi.c: > > > > > > > > > > > > A cleaner way to solve these is simply: > > > > > > > > > > > > #ifndef CONFIG_CGROUPS > > > > > > static struct psi_trigger *psi_trigger_create(...); > > > > > > ... > > > > > > #endif > > > > > > > > > > > > I tested this works: > > > > > > > > > > > > $ cat foo5.c > > > > > > static int psi(void *); > > > > > > > > > > > > int psi(void *x) > > > > > > { > > > > > > return (int)(long)x; > > > > > > } > > > > > > > > > > > > int bar(void *x) > > > > > > { > > > > > > return psi(x); > > > > > > } > > > > > > $ gcc -W -Wall -O2 -c -o foo5.o foo5.c > > > > > > $ readelf -s foo5.o > > > > > > > > > > > > Symbol table '.symtab' contains 4 entries: > > > > > > Num: Value Size Type Bind Vis Ndx Name > > > > > > 0: 0000000000000000 0 NOTYPE LOCAL DEFAULT UND > > > > > > 1: 0000000000000000 0 FILE LOCAL DEFAULT ABS foo5.c > > > > > > 2: 0000000000000000 0 SECTION LOCAL DEFAULT 1 .text > > > > > > 3: 0000000000000000 3 FUNC GLOBAL DEFAULT 1 bar > > > > > > > > > > > > > > > > Thanks Matthew! > > > > > That looks much cleaner. I'll post a separate patch to fix these. My > > > > > main concern was whether it's worth adding more code to satisfy this > > > > > warning but with this approach the code changes are minimal, so I'll > > > > > go ahead and post it shortly. > > > > > > > > Why not simply move the declarations of psi_trigger_create() and > > > > psi_trigger_destroy() in include/linux/psi.h outside of the > > > > '#ifdef CONFIG_CGROUPS' block, to match the .c file? > > > > > > IIRC this was done to avoid another warning that these functions are > > > not used outside of psi.c when CONFIG_CGROUPS=n > > > > > > > What tool gave that warning? > > Let me double-check by building it. It has been a while since I > developed the code and I don't want to mislead by making false claims. > No warnings, so it was probably done to keep the scope of these functions as local as possible. I agree that moving them out of #ifdef CONFIG_CGROUPS in the header file makes sense here. The scope unnecessarily expands when CONFIG_CGROUPS=n but the code is simpler. Will do that then. I noticed there is another warning about psi_cpu_proc_ops and similar structures being unused when CONFIG_PROC_FS=n. Looks like I'll need some more ifdefs to fix all these warnings. > > > > - Eric