Received: by 2002:ab2:710b:0:b0:1ef:a325:1205 with SMTP id z11csp1270305lql; Tue, 12 Mar 2024 11:59:16 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXhA50Mp97YRh8y0J8rQf8+HH7NPSM10nCZOTkRYQScnWGroJ6XmRImh+Dm0u12kI04a5L8FiYiIYhiI/lzbaWp7vlxRnZlFSBOFAn5XQ== X-Google-Smtp-Source: AGHT+IFxrB7Kv3D9q8baQhZH28Aox1IvsJQHLizJf69GVV8rd2e6NZ85AlFn2UY6VK1fOmNspb4f X-Received: by 2002:a17:90b:19d0:b0:29b:e0ee:8e65 with SMTP id nm16-20020a17090b19d000b0029be0ee8e65mr580810pjb.16.1710269956264; Tue, 12 Mar 2024 11:59:16 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1710269956; cv=pass; d=google.com; s=arc-20160816; b=vea3YwXR35ca0tdZpY4fn3XWSOc7uq8vygs6vPP++Az+b237HsvUZNRQLkv2nJY/pY ZggdYv9oO+Ili/fCoqT0g6cg3gGA6kzZhzrxRYGdpbI/2RZ3uh/gzBI3oKi3qWPBuO0h 4zlaOK81n22PBwHKGaCdR436eXYsVHGBxZl6iCuDgFLBGWXwAudHNJ84N8ava8KqSPAu clF/NaVbcVlOeZhEcFhnmGtAIoIiQAMXIpICGFPihq9tRnRyziRj6/LHP6/+uATcKvL0 HDNxC5uGNcDNh3Fa1EVSRrYeyCokIIJBGN1wy8jIUEpmpfT5O7AM+cL5LGKfY1SIyQVq 9KxA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:list-unsubscribe:list-subscribe :list-id:precedence:dkim-signature; bh=k2MYgtHOHaU2CXGG9+oDczn4RM3zU0YZuyP5JPwAa+g=; fh=6DeMJaSNtiAy2Rqi0D3l6VBQJH7IOiKlxKuMohwb7DM=; b=Q4369OaQPIs+d0EGowAGGGeV/YYojdkCZdycFIroOCska3vQfkzAem2NWNn2RSnWOv MOKTLPjgmP0vbFkoiqBHFK90o2GsLnEAFsJ25m1s0wkTZ1Ln08xibiRUZLnw89YGIBy3 7EMMbKvoSzGuP2mVViik6qtpMDEePAFR0sTy1XPNWNWwsv1CscoG/KHCvGjDJzI1QwGi SWH4zHgFTMkJZeZhGFMaOBlyq1Ip1QMtS0ZYJR8um4XOf9vT+bB3Ssk56CzCtTR2OY3r axUA1bHfxcMPqw4hPMGeRJXMknuIDIppZkc5W3G0WhAQ++hlE5OZq2S/FyCdHkgVFnrx YDcw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=Jm2PPML8; arc=pass (i=1 spf=pass spfdomain=google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-100681-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-100681-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id s5-20020a17090aad8500b0029b9d828c4fsi7670510pjq.86.2024.03.12.11.59.15 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Mar 2024 11:59:16 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-100681-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=Jm2PPML8; arc=pass (i=1 spf=pass spfdomain=google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-100681-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-100681-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id C29A3B22FD1 for ; Tue, 12 Mar 2024 18:42:00 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 7D5B6142623; Tue, 12 Mar 2024 18:41:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="Jm2PPML8" Received: from mail-yw1-f177.google.com (mail-yw1-f177.google.com [209.85.128.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id F012013E7DD for ; Tue, 12 Mar 2024 18:41:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.177 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710268906; cv=none; b=YTUFjdZa8Jd9jI6B3BViAKyQqdAE5StWfAaZw9ZYxoFs4g1x/IP1D6sbQQtz9xu6L+vUbhxUveAJbeQlxrDomIKo2hPmYTfOtBLZrjy1RHnxvm5s8PGNVcb0TeJ/ZzcU+ds5eHIsSAc8J/wtZ53cGWZ25tCvjzqkNsMjCkJSKgg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710268906; c=relaxed/simple; bh=sqOb2aVxWzIRPNIud0HwvwVM+i0sQ6GOvRIk6ilU6Us=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=abVxH28VMODjBQDVdY64T1SpWdsGkfiC6CXJSXLSwFaS6iUJABiEm2EPz7Juzyfk4rugqzLz97tmtyCM+jHqbC1X9N1FK5LAzByvXq6qx0/iSSaN7x509QwZHseQwXXG6RLFbXo92Q5TO/GVqJWgHBOY1Z41u4l8G99LoT1pMZg= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=Jm2PPML8; arc=none smtp.client-ip=209.85.128.177 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=google.com Received: by mail-yw1-f177.google.com with SMTP id 00721157ae682-60a0a54869bso1393997b3.1 for ; Tue, 12 Mar 2024 11:41:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1710268903; x=1710873703; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=k2MYgtHOHaU2CXGG9+oDczn4RM3zU0YZuyP5JPwAa+g=; b=Jm2PPML8v5quH3bfe9rqbFYY9G4GwVlCaraY/tLSQM7HjpeuXe1zxebYDAZ8wBAw6+ kDr/TlcLRq1qk8yRwpnjK7CrCtepwcPhUeYeqk56n3XSf12jHS/KZnnxU+jainbKNqeo q5S7ybj8JKvWJwLW5I1Z7fmdAA0bGQkoO15gRuaYgH89HkolkZAiXS2Tn6JbxRg0f3e6 ZAuBhgYERIlEIVfDRQMShMGpGTwPG+z4AcgqKLlEZmMpwNiRlE3HTtijk+0evSokROYG juZVO4fapxEkTUhAneKAa36gQvOZJlqp+xgF4OU4G8AdYdnJviV1bGUDZrZAFdIO4eGR 0F6w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710268903; x=1710873703; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=k2MYgtHOHaU2CXGG9+oDczn4RM3zU0YZuyP5JPwAa+g=; b=bc17sQ/CID6NzmoyHEJjq03QX9Bu6Xub/BT8oUoqIiAvkHs3DkyISBL3pz6D6Av/RD ypaeI05Qn2ERek2ZwDDCSxjiJWWgDOT/ehv/uc5twI1ZmzyBHeZAP2lvx8c0v0i0H7+U WjVzG7B5Ug3lIEl+dEVeQtZzbBDBfpP4QtdufgcxhjgYNvo6clF35U+b6u+IvrCoSDrg HH7gI7kGxqckBSM800vsA+JcRa5YrHfCKyINX9GKPUvwatWOZtdg2gPhc6E7OwyS5mHU gE7ztnnqDZXfxZDrTQR76rGRbs/dHyujI3v8JFz+i/U+3UOcJRiYWN7KtYuE3wb0ZyVf 4iRw== X-Forwarded-Encrypted: i=1; AJvYcCU4EhhqLApVIJykghakPkHW4G4utSXJKIP5+9VIXNokuwJpU7Vf72BpFQlRfIIV6WTLh3+d/WIn3MmXSdK6U5tykGujWKbaGdchC4Qx X-Gm-Message-State: AOJu0Yy2sqxv8Gviitp4Z4u3kraBpGD76Eo13yW8BsTlOXf4zZ6b2M8t ivj0nvXWaKH300DnPaMnuCdoeqmfwFUNBQvFTpMSJmr6uLmCj51xvClSsJtGia/AJzoyimZC5WT SK+A5/2ZG1MFQ9CBYTTUE/YetQPOXElAULlrV X-Received: by 2002:a81:e546:0:b0:609:c64a:f34b with SMTP id c6-20020a81e546000000b00609c64af34bmr292571ywm.22.1710268902597; Tue, 12 Mar 2024 11:41:42 -0700 (PDT) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20240306182440.2003814-1-surenb@google.com> <20240306182440.2003814-13-surenb@google.com> In-Reply-To: From: Suren Baghdasaryan Date: Tue, 12 Mar 2024 11:41:28 -0700 Message-ID: Subject: Re: [PATCH v5 12/37] lib: prevent module unloading if memory is not freed To: Luis Chamberlain Cc: akpm@linux-foundation.org, kent.overstreet@linux.dev, mhocko@suse.com, vbabka@suse.cz, hannes@cmpxchg.org, roman.gushchin@linux.dev, mgorman@suse.de, dave@stgolabs.net, willy@infradead.org, liam.howlett@oracle.com, penguin-kernel@i-love.sakura.ne.jp, corbet@lwn.net, void@manifault.com, peterz@infradead.org, juri.lelli@redhat.com, catalin.marinas@arm.com, will@kernel.org, arnd@arndb.de, tglx@linutronix.de, mingo@redhat.com, dave.hansen@linux.intel.com, x86@kernel.org, peterx@redhat.com, david@redhat.com, axboe@kernel.dk, masahiroy@kernel.org, nathan@kernel.org, dennis@kernel.org, jhubbard@nvidia.com, tj@kernel.org, muchun.song@linux.dev, rppt@kernel.org, paulmck@kernel.org, pasha.tatashin@soleen.com, yosryahmed@google.com, yuzhao@google.com, dhowells@redhat.com, hughd@google.com, andreyknvl@gmail.com, keescook@chromium.org, ndesaulniers@google.com, vvvvvv@google.com, gregkh@linuxfoundation.org, ebiggers@google.com, ytcoode@gmail.com, vincent.guittot@linaro.org, dietmar.eggemann@arm.com, rostedt@goodmis.org, bsegall@google.com, bristot@redhat.com, vschneid@redhat.com, cl@linux.com, penberg@kernel.org, iamjoonsoo.kim@lge.com, 42.hyeyoo@gmail.com, glider@google.com, elver@google.com, dvyukov@google.com, shakeelb@google.com, songmuchun@bytedance.com, jbaron@akamai.com, aliceryhl@google.com, rientjes@google.com, minchan@google.com, kaleshsingh@google.com, kernel-team@android.com, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, iommu@lists.linux.dev, linux-arch@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-modules@vger.kernel.org, kasan-dev@googlegroups.com, cgroups@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Tue, Mar 12, 2024 at 11:22=E2=80=AFAM Luis Chamberlain wrote: > > On Wed, Mar 06, 2024 at 10:24:10AM -0800, Suren Baghdasaryan wrote: > > Skip freeing module's data section if there are non-zero allocation tag= s > > because otherwise, once these allocations are freed, the access to thei= r > > code tag would cause UAF. > > So you just let them linger? Well, I think this is not a normal situation when a module allocated some memory and then is being unloaded without freeing that memory, no? > > > Signed-off-by: Suren Baghdasaryan > > > > /* Free a module, remove from lists, etc. */ > > static void free_module(struct module *mod) > > { > > + bool unload_codetags; > > + > > trace_module_free(mod); > > > > - codetag_unload_module(mod); > > + unload_codetags =3D codetag_unload_module(mod); > > + if (!unload_codetags) > > + pr_warn("%s: memory allocation(s) from the module still a= live, cannot unload cleanly\n", > > + mod->name); > > + > > Because this is not unwinding anything. Should'd we check if we can > free all tags first, if we can't then we can't free the module. If we > can then ensure we don't enter a state where we can't later? unload_codetags already indicates that someone has a live reference to one or more tags of that module, so we can't free them. Maybe I misunderstood your suggestion? > > Luis