Received: by 2002:a05:6500:1b45:b0:1f5:f2ab:c469 with SMTP id cz5csp1204726lqb; Thu, 18 Apr 2024 03:21:47 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUHAokgaccCMOEybmNY+PY3r2XQEyOXnMHy+WscgS8OVQVatfpxUyUokHRGDI2hqVzWCRjaAEoGyD+Qb85+okmVE8C8vdOhHIWNTqq5mg== X-Google-Smtp-Source: AGHT+IGQhD13epylquu0ilTnFO8yUm5RxqrhnA0q9IrSJgnGY99DLZyrwVEwSKHAQaXCpMNIXnmV X-Received: by 2002:a50:8d4a:0:b0:56d:f035:7db2 with SMTP id t10-20020a508d4a000000b0056df0357db2mr1489942edt.24.1713435707562; Thu, 18 Apr 2024 03:21:47 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1713435707; cv=pass; d=google.com; s=arc-20160816; b=txF4/o5syX1Z4Nt+VvO8/CeYyNaIEOlkK9qYBt74heW/eH725ncC7rGGdKcXQ3I2j3 iWGLTqRlCmJhBz0O2WjQAhMDnjNDWECT8kyu1pVuKIc/yw3caS8s5N+XJiOZMrPgb3yT IphrwV0LPpi0IRBrb5wQysz92YpnY61Fj3wLe9vbNjkIAztxk7myM5BVtMkpUDhYjZtY zr2o6J2EvCCiTF2njIZGK3LGYpdRTqGJxXvzuAMpLhc7+cnGuSXUP2P4nbh4em6LvvXU 8S6qDVdBDsrYHyhe7wTdiZuW/dM701Z2PTcVd508ezWdSJBfIHxbX8dikcHNwWFeMXsW +raQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :references:message-id:subject:cc:to:from:date:dkim-signature; bh=Yrxw2v75Z+TZKXmyCGe4anySq6+8O+YA0ImUt5EDUTk=; fh=7i6s7RbdXICvhOa8L0+lGne4ntOuFTLxD2WUMA4R3K4=; b=xVQv6knGGv61kQZOGLIWqi0kdyLo5aCRmDOGaso6cnzNN4jfNBOUVGygXqJ3cKPH6V 5j/LyyDkHQCf+S7shkHKnEm1YgX8a5zIZMSrx1s0P2Ih9YwJHsLn+yYStLGHVzmjC2Hr XmJdP1dNPNQ2fD73b7tSBT71aNXbBsaqaNMXRJuafG7DHHb0hAS8yWihPqXX92xlC+0c O4r2VirHDd0gQ9FAwJp7KoSji3DSCNJDV+sUAwIpbAXHmM2RnFqYYXmExB0/cckwfuLG KEHZkAC+oJUx+SlxCSgE32pKdk9DKpupBtU5XGD5lsJqIMFEGFLKl+SWAhTwk8V/jAlZ 2Jew==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=SELAoNeX; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-149873-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-149873-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id w25-20020aa7da59000000b0056e2a6d63f7si682927eds.20.2024.04.18.03.21.47 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 Apr 2024 03:21:47 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-149873-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=SELAoNeX; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-149873-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-149873-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org 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 am.mirrors.kernel.org (Postfix) with ESMTPS id ED7CC1F218BA for ; Thu, 18 Apr 2024 10:21:46 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 8A68A15CD47; Thu, 18 Apr 2024 10:21:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="SELAoNeX" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9C86D15AAD9; Thu, 18 Apr 2024 10:21:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713435694; cv=none; b=bd7/6N5LhhhYbfab3j82Zk/0Cg/PMjHbOC+Fwb1U4CI4wf4P4Ljjyx+4zS8eOYhtJyHU5iSm1oegfZJgTQHgRp21m1dIc5L5ldKYgW6imos+OynGcy7GWLrpuzqv0J4ZklTp7E2OSB4HNjuv7miARB0nJVeIJDAdXHcXfYocrSA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713435694; c=relaxed/simple; bh=GIF39x+DoxCddvDNRomXCworfiQAca8ygUjDy3+kOkw=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=EgpGF4OF2T51IvROcPFCNlgkLQPpqYIMOyAm+tqk2ViNJUx0g4QjNfjeYKbVtuR3IJ9Tz0JMB9OkrYoxdBSrM8NuPf6FOq3Bgb70tS0mjlLVD3QUv9rPabXmP1+57eQhs8/ESsl9O8A0dyfT5ecgorpjUBnq8GjtUJOxoK0QYtc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=SELAoNeX; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id CDE78C113CC; Thu, 18 Apr 2024 10:21:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1713435694; bh=GIF39x+DoxCddvDNRomXCworfiQAca8ygUjDy3+kOkw=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=SELAoNeXc3Beu0HbaRnXjo5QYZwKVoBtQiv3DGWKIGD1ByoQxYtKIRMmvzmqWXRIs l28WXlrgf45drPhQ9fcY+C862qqlcZ84I3lISaD2oLaKCzcGbAykPBulJ9k6bwvlRz LV8NaKjnWubu4ei2CwJbivkB4YEQEKSRsSyVzaW8Mxs5W6YReOjEi+EuEAD86bBnwS qFPhIxsVlHHsOebyI08OR68Lghu75Srbh8a5UrbpGFwRlRYkMIVyzmMjHu+Dqlrqq9 fLqc6ctyg9Ep6vn3VgTN09QBUzcZ5AVisQI/jdvTkZRhUWxPwNNaW0QWW5GqKdhOFZ JlWziN6p3qThQ== Date: Thu, 18 Apr 2024 13:20:17 +0300 From: Mike Rapoport To: Nadav Amit Cc: Linux Kernel Mailing List , Andrew Morton , Andy Lutomirski , Arnd Bergmann , Catalin Marinas , Christoph Hellwig , Helge Deller , Lorenzo Stoakes , Luis Chamberlain , Mark Rutland , Masami Hiramatsu , Mathieu Desnoyers , Michael Ellerman , Palmer Dabbelt , Peter Zijlstra , Russell King , Song Liu , Steven Rostedt , Thomas Gleixner , Uladzislau Rezki , Will Deacon , bpf@vger.kernel.org, linux-arch@vger.kernel.org, linux-arm-kernel@lists.infradead.org, "open list:MEMORY MANAGEMENT" , linux-modules@vger.kernel.org, linux-parisc@vger.kernel.org, linux-riscv@lists.infradead.org, linux-trace-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, the arch/x86 maintainers Subject: Re: [RFC PATCH 3/7] module: prepare to handle ROX allocations for text Message-ID: References: <20240411160526.2093408-1-rppt@kernel.org> <20240411160526.2093408-4-rppt@kernel.org> <0C4B9C1A-97DE-4798-8256-158369AF42A4@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <0C4B9C1A-97DE-4798-8256-158369AF42A4@gmail.com> On Tue, Apr 16, 2024 at 12:36:08PM +0300, Nadav Amit wrote: > > > > On 11 Apr 2024, at 19:05, Mike Rapoport wrote: > > > > @@ -2440,7 +2479,24 @@ static int post_relocation(struct module *mod, const struct load_info *info) > > add_kallsyms(mod, info); > > > > /* Arch-specific module finalizing. */ > > - return module_finalize(info->hdr, info->sechdrs, mod); > > + ret = module_finalize(info->hdr, info->sechdrs, mod); > > + if (ret) > > + return ret; > > + > > + for_each_mod_mem_type(type) { > > + struct module_memory *mem = &mod->mem[type]; > > + > > + if (mem->is_rox) { > > + if (!execmem_update_copy(mem->base, mem->rw_copy, > > + mem->size)) > > + return -ENOMEM; > > + > > + vfree(mem->rw_copy); > > + mem->rw_copy = NULL; > > + } > > + } > > + > > + return 0; > > } > > I might be missing something, but it seems a bit racy. > > IIUC, module_finalize() calls alternatives_smp_module_add(). At this > point, since you don’t hold the text_mutex, some might do text_poke(), > e.g., by enabling/disabling static-key, and the update would be > overwritten. No? Right :( Even worse, for UP case alternatives_smp_unlock() will "patch" still empty area. So I'm thinking about calling alternatives_smp_module_add() from an additional callback after the execmem_update_copy(). Does it make sense to you? -- Sincerely yours, Mike.