From patchwork Wed Jul 26 10:57:56 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13327839 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 C0C09C001B0 for ; Wed, 26 Jul 2023 10:58:06 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 5D8858D0001; Wed, 26 Jul 2023 06:58:06 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 588E06B0075; Wed, 26 Jul 2023 06:58:06 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 477C78D0001; Wed, 26 Jul 2023 06:58:06 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 393846B0071 for ; Wed, 26 Jul 2023 06:58:06 -0400 (EDT) Received: from smtpin02.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 00EEB1C9BEF for ; Wed, 26 Jul 2023 10:58:05 +0000 (UTC) X-FDA: 81053463330.02.E230CC7 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf22.hostedemail.com (Postfix) with ESMTP id 11D2AC0008 for ; Wed, 26 Jul 2023 10:58:02 +0000 (UTC) Authentication-Results: imf22.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b="ck8F/PSy"; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf22.hostedemail.com: domain of dhowells@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=dhowells@redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1690369083; 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: references:dkim-signature; bh=jGubfG0J6/LbJU8ZklZwV88L9biaQyHs5qooncbU0FI=; b=QcUBMuBSjLZhdudoVZepBpQc8eTLV0AykGhdnpUaVUT2G/7lUsg55mrgaj8ijyYLPkz7aX S+rsYM/s5fwVoXFMW1Pmk8qKNMRSICGT33KM12O6s9kQEPaQTJrP8m6ZQR10kbAZfRYXEp wU8wmNur6BEdoV+eDna9qMrSDkVoLVw= ARC-Authentication-Results: i=1; imf22.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b="ck8F/PSy"; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf22.hostedemail.com: domain of dhowells@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=dhowells@redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1690369083; a=rsa-sha256; cv=none; b=8lEIqRZUNm1imQWQCVKpSD4DPMkvF/5zec1gXcrzrXOpYA1aCuOikW7HPzyAdTYwoHG2C+ 06JdbCsgZNSSQhTAlBxsM8HJZImPhvDFmO0uGQdrcBRUeQIY34+RXFKDprdysbnGWWgv9r yCV1LVY3qrMK+p5Vu/FHMxmWQtlr9uA= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1690369082; 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; bh=jGubfG0J6/LbJU8ZklZwV88L9biaQyHs5qooncbU0FI=; b=ck8F/PSyOMUcO7/BmS+5AfY47TIUTemNJxL+QM1cAvm0PnmZb5jdF8KzZIvlSqEwAg+T81 tgc9RhlW8XK4OYvcXr2+xcFLjKVgp81FnQTHjkTDmuRrk+uTtilz7SdJ81bLlQJWjU1l45 aFx4ZtYzfa2yFw1SlBLKOxrbDgvIvJY= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-206-dqoDG2KSNXWgfEIc4HVvzQ-1; Wed, 26 Jul 2023 06:58:00 -0400 X-MC-Unique: dqoDG2KSNXWgfEIc4HVvzQ-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 7327F801CF3; Wed, 26 Jul 2023 10:57:59 +0000 (UTC) Received: from warthog.procyon.org.uk (unknown [10.42.28.158]) by smtp.corp.redhat.com (Postfix) with ESMTP id DA5BE2166B25; Wed, 26 Jul 2023 10:57:56 +0000 (UTC) Organization: Red Hat UK Ltd. Registered Address: Red Hat UK Ltd, Amberley Place, 107-111 Peascod Street, Windsor, Berkshire, SI4 1TE, United Kingdom. Registered in England and Wales under Company Registration No. 3798903 From: David Howells To: Herbert Xu , Steve French cc: dhowells@redhat.com, akpm@linux-foundation.org, Sven Schnelle , "David S. Miller" , Jeff Layton , Shyam Prasad N , Rohith Surabattula , Jens Axboe , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Matthew Wilcox , linux-mm@kvack.org, linux-crypto@vger.kernel.org, linux-cachefs@redhat.com, linux-cifs@vger.kernel.org, linux-fsdevel@vger.kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] crypto, cifs: Fix error handling in extract_iter_to_sg() MIME-Version: 1.0 Content-ID: <20570.1690369076.1@warthog.procyon.org.uk> Date: Wed, 26 Jul 2023 11:57:56 +0100 Message-ID: <20571.1690369076@warthog.procyon.org.uk> X-Scanned-By: MIMEDefang 3.1 on 10.11.54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RJ7DAc/r61viT5omhUKeYw+Taz dzExXBZe TCntOxvhzU+dS1yfR9MZSiMpzJnQbmKIOBnkRdJLNFALSqMUhFnpbJDUNFZuxh0coPsl4nCeqKT+BnO8piOadqu/xgbi8WfA8XO/LqpBAZ9q12kDuE3hLUbwNLItS3I3BWJgLSwYizeD+FOec3o1Psi6ilvSUeSOV/GfX7h4MZvfDbZ2YEQWqC0lOig8Uyg3Jdb4Ot0FZJlY4f+CRGeoANQPul8oXFJ6NGy3JVpan9HFKHZ7/uKOG8HyJk4rPXo+SOwgvPcdhyKzR6JdeDVKz9UALM26Et47aPQmv+tFy4l9B0MH1Xj+RyQiuS/w99abbfd8XVblG1bym01tJFX2b9erC+FvmJ0Wuv+OBEmAq53/gX1oFI2yYqg/KK38kRj9PXkyzi7VCfvuSYdGIu0Fc6shfEDe92aGJXjImjjZLBK+Gd7m3Lvu3I6FA3aWYgOErfdaUuakyJx668SWVds9KpZnxhLD6+70qzA3+daFIcUN1Zo+3kIodcWb3kCdq1F4lWeCSwgn1vrYj5XxvuxTEaFYlC1D8vFlYt2i6zl+9c9+hkdiX+sPrMTgeIR8FbHokyKbKcWI6xIVs5uTwnEIdKN6Lf9A/ST02WfVT7hY+n+lA1oi02rpOfh++EayhDQKB9hQbdur1mLfH9Mm6RvW2ythGxSe/Re88Z5JoKE3IMFn/rt/b7axgFkfqAE/cDOa1H/SJ9QcX0c0qIpYYantqAjv9hcVS0xWG9wsg1DZxZ3rTHsyCBkMXFvMhFQPgKhBnWVOxlUYSEZks8JC6h+/fIgMVu3dmsg5TIdFK2T9rvKpjw+bCy9fcwUzxwpQqI0r/gVXGOrvfmE9ScvsDS3osxFW4Jg== 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: Fix error handling in extract_iter_to_sg(). Pages need to be unpinned, not put in extract_user_to_sg() when handling IOVEC/UBUF sources. The bug may result in a warning like the following: WARNING: CPU: 1 PID: 20384 at mm/gup.c:229 __lse_atomic_add arch/arm64/include/asm/atomic_lse.h:27 [inline] WARNING: CPU: 1 PID: 20384 at mm/gup.c:229 arch_atomic_add arch/arm64/include/asm/atomic.h:28 [inline] WARNING: CPU: 1 PID: 20384 at mm/gup.c:229 raw_atomic_add include/linux/atomic/atomic-arch-fallback.h:537 [inline] WARNING: CPU: 1 PID: 20384 at mm/gup.c:229 atomic_add include/linux/atomic/atomic-instrumented.h:105 [inline] WARNING: CPU: 1 PID: 20384 at mm/gup.c:229 try_grab_page+0x108/0x160 mm/gup.c:252 ... pc : try_grab_page+0x108/0x160 mm/gup.c:229 lr : follow_page_pte+0x174/0x3e4 mm/gup.c:651 ... Call trace: __lse_atomic_add arch/arm64/include/asm/atomic_lse.h:27 [inline] arch_atomic_add arch/arm64/include/asm/atomic.h:28 [inline] raw_atomic_add include/linux/atomic/atomic-arch-fallback.h:537 [inline] atomic_add include/linux/atomic/atomic-instrumented.h:105 [inline] try_grab_page+0x108/0x160 mm/gup.c:252 follow_pmd_mask mm/gup.c:734 [inline] follow_pud_mask mm/gup.c:765 [inline] follow_p4d_mask mm/gup.c:782 [inline] follow_page_mask+0x12c/0x2e4 mm/gup.c:839 __get_user_pages+0x174/0x30c mm/gup.c:1217 __get_user_pages_locked mm/gup.c:1448 [inline] __gup_longterm_locked+0x94/0x8f4 mm/gup.c:2142 internal_get_user_pages_fast+0x970/0xb60 mm/gup.c:3140 pin_user_pages_fast+0x4c/0x60 mm/gup.c:3246 iov_iter_extract_user_pages lib/iov_iter.c:1768 [inline] iov_iter_extract_pages+0xc8/0x54c lib/iov_iter.c:1831 extract_user_to_sg lib/scatterlist.c:1123 [inline] extract_iter_to_sg lib/scatterlist.c:1349 [inline] extract_iter_to_sg+0x26c/0x6fc lib/scatterlist.c:1339 hash_sendmsg+0xc0/0x43c crypto/algif_hash.c:117 sock_sendmsg_nosec net/socket.c:725 [inline] sock_sendmsg+0x54/0x60 net/socket.c:748 ____sys_sendmsg+0x270/0x2ac net/socket.c:2494 ___sys_sendmsg+0x80/0xdc net/socket.c:2548 __sys_sendmsg+0x68/0xc4 net/socket.c:2577 __do_sys_sendmsg net/socket.c:2586 [inline] __se_sys_sendmsg net/socket.c:2584 [inline] __arm64_sys_sendmsg+0x24/0x30 net/socket.c:2584 __invoke_syscall arch/arm64/kernel/syscall.c:38 [inline] invoke_syscall+0x48/0x114 arch/arm64/kernel/syscall.c:52 el0_svc_common.constprop.0+0x44/0xe4 arch/arm64/kernel/syscall.c:142 do_el0_svc+0x38/0xa4 arch/arm64/kernel/syscall.c:191 el0_svc+0x2c/0xb0 arch/arm64/kernel/entry-common.c:647 el0t_64_sync_handler+0xc0/0xc4 arch/arm64/kernel/entry-common.c:665 el0t_64_sync+0x19c/0x1a0 arch/arm64/kernel/entry.S:591 Fixes: 018584697533 ("netfs: Add a function to extract an iterator into a scatterlist") Reported-by: syzbot+9b82859567f2e50c123e@syzkaller.appspotmail.com Link: https://lore.kernel.org/linux-mm/000000000000273d0105ff97bf56@google.com/ Signed-off-by: David Howells cc: Sven Schnelle cc: akpm@linux-foundation.org cc: Herbert Xu cc: "David S. Miller" cc: Jeff Layton cc: Steve French cc: Shyam Prasad N cc: Rohith Surabattula cc: Jens Axboe cc: Herbert Xu cc: "David S. Miller" cc: Eric Dumazet cc: Jakub Kicinski cc: Paolo Abeni cc: Matthew Wilcox cc: linux-mm@kvack.org cc: linux-crypto@vger.kernel.org cc: linux-cachefs@redhat.com cc: linux-cifs@vger.kernel.org cc: linux-fsdevel@vger.kernel.org cc: netdev@vger.kernel.org Reviewed-by: David Hildenbrand --- lib/scatterlist.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/scatterlist.c b/lib/scatterlist.c index e86231a44c3d..c65566b4dc66 100644 --- a/lib/scatterlist.c +++ b/lib/scatterlist.c @@ -1148,7 +1148,7 @@ static ssize_t extract_user_to_sg(struct iov_iter *iter, failed: while (sgtable->nents > sgtable->orig_nents) - put_page(sg_page(&sgtable->sgl[--sgtable->nents])); + unpin_user_page(sg_page(&sgtable->sgl[--sgtable->nents])); return res; }