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 X-Spam-Level: X-Spam-Status: No, score=-3.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7D176C4320A for ; Sat, 28 Aug 2021 19:32:48 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5C6AE604D7 for ; Sat, 28 Aug 2021 19:32:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231877AbhH1Tdg (ORCPT ); Sat, 28 Aug 2021 15:33:36 -0400 Received: from zeniv-ca.linux.org.uk ([142.44.231.140]:33570 "EHLO zeniv-ca.linux.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231258AbhH1Tdf (ORCPT ); Sat, 28 Aug 2021 15:33:35 -0400 Received: from viro by zeniv-ca.linux.org.uk with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1mK401-00GsRY-Fl; Sat, 28 Aug 2021 19:28:17 +0000 Date: Sat, 28 Aug 2021 19:28:17 +0000 From: Al Viro To: Linus Torvalds Cc: Andreas Gruenbacher , Christoph Hellwig , "Darrick J. Wong" , Jan Kara , Matthew Wilcox , cluster-devel , linux-fsdevel , Linux Kernel Mailing List , ocfs2-devel@oss.oracle.com, Josef Bacik , Catalin Marinas , Will Deacon Subject: [RFC][arm64] possible infinite loop in btrfs search_ioctl() Message-ID: References: <20210827164926.1726765-1-agruenba@redhat.com> <20210827164926.1726765-6-agruenba@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Sender: Al Viro Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org AFAICS, a48b73eca4ce "btrfs: fix potential deadlock in the search ioctl" has introduced a bug at least on arm64. Relevant bits: in search_ioctl() we have while (1) { ret = fault_in_pages_writeable(ubuf + sk_offset, *buf_size - sk_offset); if (ret) break; ret = btrfs_search_forward(root, &key, path, sk->min_transid); if (ret != 0) { if (ret > 0) ret = 0; goto err; } ret = copy_to_sk(path, &key, sk, buf_size, ubuf, &sk_offset, &num_found); btrfs_release_path(path); if (ret) break; } and in copy_to_sk() - sh.objectid = key->objectid; sh.offset = key->offset; sh.type = key->type; sh.len = item_len; sh.transid = found_transid; /* * Copy search result header. If we fault then loop again so we * can fault in the pages and -EFAULT there if there's a * problem. Otherwise we'll fault and then copy the buffer in * properly this next time through */ if (copy_to_user_nofault(ubuf + *sk_offset, &sh, sizeof(sh))) { ret = 0; goto out; } with sk_offset left unchanged if the very first copy_to_user_nofault() fails. Now, consider a situation on arm64 where ubuf points to the beginning of page, ubuf[0] can be accessed, but ubuf[16] can not (possible with MTE, AFAICS). We do fault_in_pages_writeable(), which succeeds. When we get to copy_to_user_nofault() we fail as soon as it gets past the first 16 bytes. And we repeat everything from scratch, with no progress made, since short copies are treated as "discard and repeat" here. Am I misreading what's going on there?