From mboxrd@z Thu Jan 1 00:00:00 1970 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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 682D0C021A0 for ; Wed, 12 Feb 2025 02:19:18 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id AF2E06B0082; Tue, 11 Feb 2025 21:19:17 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id AA22F6B0083; Tue, 11 Feb 2025 21:19:17 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9906C6B0085; Tue, 11 Feb 2025 21:19:17 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 809BA6B0082 for ; Tue, 11 Feb 2025 21:19:17 -0500 (EST) Received: from smtpin12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 0E32DB23F1 for ; Wed, 12 Feb 2025 02:19:17 +0000 (UTC) X-FDA: 83109685554.12.202B3A4 Received: from out-181.mta1.migadu.com (out-181.mta1.migadu.com [95.215.58.181]) by imf23.hostedemail.com (Postfix) with ESMTP id 2E6A8140006 for ; Wed, 12 Feb 2025 02:19:14 +0000 (UTC) Authentication-Results: imf23.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=SIRgrEVz; spf=pass (imf23.hostedemail.com: domain of shakeel.butt@linux.dev designates 95.215.58.181 as permitted sender) smtp.mailfrom=shakeel.butt@linux.dev; dmarc=pass (policy=none) header.from=linux.dev ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1739326755; a=rsa-sha256; cv=none; b=msoNE3PLEta/rF4c5XcU+21tPdT2kDMu9DIm2IMYIzdHoc6qu2c39c1VTwbWUmOxMeV7np h26NCipRzCvteRoUp5HwQJ2kX4QDRYLac1VsUH/RzVvz2jou8cn8GxmaZDrHXVFVtB4Lwb wW6dAgFPqHjhtVdQErR9RfdFq4SVEB0= ARC-Authentication-Results: i=1; imf23.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=SIRgrEVz; spf=pass (imf23.hostedemail.com: domain of shakeel.butt@linux.dev designates 95.215.58.181 as permitted sender) smtp.mailfrom=shakeel.butt@linux.dev; dmarc=pass (policy=none) header.from=linux.dev ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1739326755; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=B/PrdOYf+cocVZXALOGcooQ2F4OMml7rld1/5kS0xM4=; b=CjHu9RRsUCfDWHwRsPrVEgH87mTEOz/pSW4SeDZNYtj5H4MnvidyKtaZxABcZAmwiGwfyJ WsVs5oljcxaHjlOdTjk4g1OZxd/j8L/Cn1ojB4oYhXH5V1vV30keWe7e5+aZfXU4xnoeBn nVLUbslS1f5qMl9Ar9ZT7uCzne7Qs5Y= Date: Tue, 11 Feb 2025 18:19:08 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1739326753; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=B/PrdOYf+cocVZXALOGcooQ2F4OMml7rld1/5kS0xM4=; b=SIRgrEVzouk2U29247DrdXzcPbTxZbnaW97zmnUqFCx90sKyxOcwTXA/l7SOCLmSkHVrxz KQhP/vY+y0Ie+chX4Rv1HEvECTyghRepdlqZ/yDvVUOvwwEnKe8WgnyPnQD84C3IDoWHEC 9syG0KTu0G05wfS2zh0jAeaS83ZtZ7k= X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Shakeel Butt To: Andrii Nakryiko Cc: Jordan Rome , bpf@vger.kernel.org, linux-mm@kvack.org, Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Kernel Team , Andrew Morton , Alexander Potapenko Subject: Re: [bpf-next v7 1/3] mm: add copy_remote_vm_str Message-ID: References: <20250210221626.2098522-1-linux@jordanrome.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: X-Migadu-Flow: FLOW_OUT X-Stat-Signature: 4nb8xamha68ptib51rzyj8sjy65wr4a7 X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 2E6A8140006 X-Rspam-User: X-HE-Tag: 1739326754-149594 X-HE-Meta: U2FsdGVkX1/eVZwePacR2ffc9YvuMub765g+3OUjGcPVrrn8uSaCbxXOEoXD/khZuJeLVjKYsGrYSfgpw54Z+kUnJz4iQNcb5YXrUNgOHqf2+snbv3daOH8K3eYTGAJzNnfXSIbBo4aRUjHBm2kKcNuIxb7rC3fo4lVnQTeF75ef0ZzFQDdZkkpxzOemNwrmDKLno8WoZ+OzJDIqQPjYJyaaSI6W6DpFoCLZvNrABtTHdMxTZUOxNZJoYxHZPW3WEMzaJymi3TypVNgQgRQE2Fnlyt800d2jtjwJJBlLPD+q9jCvXwjWkYXCyOKc89Tro+RDLrB5xfAuow1Cd9Lp2Kq10qUYztEex9Sg09L7tymoq3rrrj+k1UX2krMWZlaGtyVnDix7GzMrUKw6sXUBdOAZFFFtm/sviLmwrH5g1epbfLx008PPuUDmeUMBxVijFcl7cDhQQw7Y/vogb1qO2D+3HNEUy85KgyjSMrU/Woi/pE4smqxCmY2fmY1w3wmM8ImT/46EU4HZNTF18KVlS6R5xWYaySHj+CVagBuAayZsQc8tSwEZLiUO+u74UVxm30HnysEoF9ejlGy+AUX8CWdZZi2Yf85//h8QOnxP6YSmfCOxPM4CYK1Fs+YQThuXlWUvijU64s4LMjV5tLwdKTo/h3mQIxft4YB8O2xMTMTc/WIkr8XBPz22bCAgf79hN4xdfvwhVvFvXnTeC4YmC2c8nTT/kZxe/Ms+SR+YJmM7ESvoBOOUPHzatzyWU7T2/LwPlGEaiGd3AWka+YKuAdtgHqmUBp42Pr4EabEr/Dx6pGoZPAWzSyjjTUqgyQxU6CdZAEAufCCGSH3y8Bn5jSLMb3ielLJc8vOyaW4YeceHIis6mU2BXXPsjo0ulCeu90npB6NBQ75alxuJruiNoOtKy138uNIVFMDTLx8QihdZV0FP4/VBOpf1ObdzH+Shc8CLocexIoX1XH5ZGAh lcamiI5V W4Qs1iOZqU3tBDDTMnP/EiyFULFDNwWJo0+ZPUvEw5pYRUpt+30bp1kU7y6BQQxEVYC0sGrgTlHEBXLZ5NIstQH2QAficepP0KG/vmcMDFh2LiYysOLi0kJCSSY3wjh+fsvGthQxWQB/lyr9f7D/JRuJYii6ydXHgVlpTxZoESSYx2PIZLuOKdDyBoelo4Mf1K1PRtPV/gfRHeX74nKpoRiAVFyvVsdF/1v65W63HRnEvcnUZJFosQ+zUKrnUdTrOCICWyuRF7ulW9Mvws+zDmc5YRpZtcKHeIipiYlRldWsft5tY6z5WC7XFebkTSeU/qTDE1wn6rM1GFTv/jHtoJe8WtDXBJ2JeXLd+/ywaLNFWXSLDi0o42KUya5UatdyqfYj0I8Sp8vIBGgVDb2WNQ8tDHQ== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: On Tue, Feb 11, 2025 at 02:07:31PM -0800, Andrii Nakryiko wrote: > On Mon, Feb 10, 2025 at 2:23 PM Jordan Rome wrote: > > > > Similar to `access_process_vm` but specific to strings. > > Also chunks reads by page and utilizes `strscpy` > > for handling null termination. > > > > Signed-off-by: Jordan Rome > > --- > > include/linux/mm.h | 3 ++ > > mm/memory.c | 119 +++++++++++++++++++++++++++++++++++++++++++++ > > mm/nommu.c | 73 +++++++++++++++++++++++++++ > > 3 files changed, 195 insertions(+) > > > > diff --git a/include/linux/mm.h b/include/linux/mm.h > > index 7b1068ddcbb7..aee23d84ce01 100644 > > --- a/include/linux/mm.h > > +++ b/include/linux/mm.h > > @@ -2486,6 +2486,9 @@ extern int access_process_vm(struct task_struct *tsk, unsigned long addr, > > extern int access_remote_vm(struct mm_struct *mm, unsigned long addr, > > void *buf, int len, unsigned int gup_flags); > > > > +extern int copy_remote_vm_str(struct task_struct *tsk, unsigned long addr, > > + void *buf, int len, unsigned int gup_flags); > > + > > long get_user_pages_remote(struct mm_struct *mm, > > unsigned long start, unsigned long nr_pages, > > unsigned int gup_flags, struct page **pages, > > diff --git a/mm/memory.c b/mm/memory.c > > index 539c0f7c6d54..e9d8584a7f56 100644 > > --- a/mm/memory.c > > +++ b/mm/memory.c > > @@ -6803,6 +6803,125 @@ int access_process_vm(struct task_struct *tsk, unsigned long addr, > > } > > EXPORT_SYMBOL_GPL(access_process_vm); > > > > +/* > > + * Copy a string from another process's address space as given in mm. > > + * If there is any error return -EFAULT. > > + */ > > +static int __copy_remote_vm_str(struct mm_struct *mm, unsigned long addr, > > + void *buf, int len, unsigned int gup_flags) > > +{ > > + void *old_buf = buf; > > + int err = 0; > > + > > + *(char *)buf = '\0'; > > LGTM overall: > > Acked-by: Andrii Nakryiko > > But note that all this unconditional buf access will be incorrect if > len == 0. So either all of that has to be guarded with `if (len)`, > just dropped, or declared unsupported, depending on what mm folks > think. BPF helper won't ever call with len == 0, so that's why my ack. I think early return 0 on len == 0 should be fine.