Received: by 2002:a05:7412:8d11:b0:fa:4934:9f with SMTP id bj17csp438888rdb; Mon, 15 Jan 2024 02:08:57 -0800 (PST) X-Google-Smtp-Source: AGHT+IHTM+vEXDpiDuvDsGA7uedDkMsqnFJb04GRfNvdQ12Tz7hJxPyX+0zn8ad3CZTDYPHpNMjs X-Received: by 2002:a17:902:7c08:b0:1d4:752f:9d18 with SMTP id x8-20020a1709027c0800b001d4752f9d18mr5469525pll.139.1705313337529; Mon, 15 Jan 2024 02:08:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1705313337; cv=none; d=google.com; s=arc-20160816; b=T7dUo102mVh1ZuCQj8daNrrxQQLXoyj88OqJLmSN4Jy9Ot67DyqQRhuMGgdJlm1w/v kQ0SO/soj+El2ae/K/mpUof4OO5p4fFQpMZti+klJE1opAn+ZgWMXq4d+dCCbRmhrpuR xKRqDlBgGxfRQBNd5XvjQwZiZo1czCRBA/HvZ2E3qNMjzVGo8ktZlN58h/hAKK0mpJqp CDHuqP23yR7FCiB648tMO4kk3XHhoL/RnuF8c6q6Qje944KNJ7SO8ikpQnYSpKTszcoo NASRfYfhWztAr3ZMmD3fxzxkQPKFEFlMH8USqc3ZmbwQ+PXnPStiMWNAeFpvv2FJu3dj DdZw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from:dkim-signature; bh=5T4EASqZP4WNXzIQNT1K4h8oNNu89D6KQhpLw+uTpdE=; fh=d2XVlTdUeF73jCuv1p6EtPVhSm3M4VJf/Eqg7brm4u4=; b=iGXr1FjADwryxg99FPGsiKTNXcpWl/gyA+FSAgHNfZAgt1Fv1Na5IQSu5U69kpsTc5 8MgHNO6N54mq9M86GgDp7pCSajLgjS9j/zgFaSGo7gdPtqUK2u6uWDnhLT3Y//eRhyKe OuErdDPCd6IMW+cv3JN0oPIeibtZikoaeDE16FH6i29XrjAHKGLgdw8PmKkjNLWJKcyr Wp3IB5NBl2R5ZsixT0lPJyj266+cEgdd79GfSgE7R8Nz/ylrQXYRDbASDzdawddMfH0j 4U0ZHr3PRVSXSivyHB9ZgaR+MtVxxdD91AeziKllKZqLw92C7F6A/w6flAVd8cOMGVOK NyAw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=hn4rX1ua; spf=pass (google.com: domain of linux-kernel+bounces-25855-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-25855-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id jb4-20020a170903258400b001d465594d43si8290821plb.87.2024.01.15.02.08.57 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 Jan 2024 02:08:57 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-25855-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=hn4rX1ua; spf=pass (google.com: domain of linux-kernel+bounces-25855-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-25855-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 2F31B2825DB for ; Mon, 15 Jan 2024 10:08:08 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A6A2DF9C2; Mon, 15 Jan 2024 10:07:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="hn4rX1ua" Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (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 70E51F4E7 for ; Mon, 15 Jan 2024 10:07:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1705313260; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=5T4EASqZP4WNXzIQNT1K4h8oNNu89D6KQhpLw+uTpdE=; b=hn4rX1uaRv9UreJ4kBteFDcXAqNXgrYQgPuE+VnmeRdlW5GOlOdl+2iirDEyPxD4EmRvbI mB+zw3IPPloHc9cC31FTDCK8LQGzRNGWtV8/S/3Bmz5bxMyQcstUxWcRKwdJwDCZg6dtjV shI1IHC4GOJ2Ad9V+PkzAVZdib746PY= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-563-7P3tQoYOPIKCU7iP2YPC5w-1; Mon, 15 Jan 2024 05:07:37 -0500 X-MC-Unique: 7P3tQoYOPIKCU7iP2YPC5w-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 653CF38425A0; Mon, 15 Jan 2024 10:07:36 +0000 (UTC) Received: from t14s.redhat.com (unknown [10.39.194.130]) by smtp.corp.redhat.com (Postfix) with ESMTP id DFBA040C6E2C; Mon, 15 Jan 2024 10:07:32 +0000 (UTC) From: David Hildenbrand To: linux-kernel@vger.kernel.org Cc: linux-mm@kvack.org, linux-perf-users@vger.kernel.org, David Hildenbrand , Jiri Olsa , Ryan Roberts , Andrew Morton , Oleg Nesterov , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Namhyung Kim , Ian Rogers , Adrian Hunter Subject: [PATCH v1] uprobes: use pagesize-aligned virtual address when replacing pages Date: Mon, 15 Jan 2024 11:07:31 +0100 Message-ID: <20240115100731.91007-1-david@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.2 uprobes passes an unaligned page mapping address to folio_add_new_anon_rmap(), which ends up triggering a VM_BUG_ON() we recently extended in commit 372cbd4d5a066 ("mm: non-pmd-mappable, large folios for folio_add_new_anon_rmap()"). Arguably, this is uprobes code doing something wrong; however, for the time being it would have likely worked in rmap code because __folio_set_anon() would set folio->index to the same value. Looking at __replace_page(), we'd also pass slightly wrong values to mmu_notifier_range_init(), page_vma_mapped_walk(), flush_cache_page(), ptep_clear_flush() and set_pte_at_notify(). I suspect most of them are fine, but let's just mark the introducing commit as the one needed fixing. I don't think CC stable is warranted. We'll add more sanity checks in rmap code separately, to make sure that we always get properly aligned addresses. Reported-by: Jiri Olsa Closes: https://lkml.kernel.org/r/ZaMR2EWN-HvlCfUl@krava Fixes: c517ee744b96 ("uprobes: __replace_page() should not use page_address_in_vma()") Tested-by: Jiri Olsa Reviewed-by: Ryan Roberts Cc: Andrew Morton Cc: Oleg Nesterov Cc: Peter Zijlstra Cc: Ingo Molnar Cc: Arnaldo Carvalho de Melo Cc: Mark Rutland Cc: Alexander Shishkin Cc: Jiri Olsa Cc: Namhyung Kim Cc: Ian Rogers Cc: Adrian Hunter Signed-off-by: David Hildenbrand --- kernel/events/uprobes.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kernel/events/uprobes.c b/kernel/events/uprobes.c index 485bb0389b488..929e98c629652 100644 --- a/kernel/events/uprobes.c +++ b/kernel/events/uprobes.c @@ -537,7 +537,7 @@ int uprobe_write_opcode(struct arch_uprobe *auprobe, struct mm_struct *mm, } } - ret = __replace_page(vma, vaddr, old_page, new_page); + ret = __replace_page(vma, vaddr & PAGE_MASK, old_page, new_page); if (new_page) put_page(new_page); put_old: -- 2.43.0