Received: by 2002:a05:6a10:17d3:0:0:0:0 with SMTP id hz19csp1313934pxb; Sat, 17 Apr 2021 13:33:14 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyQ5aLN8tR5dl0iDT6xmad1W4BEDEU8w2hAaQTcjL+UUALIKszuZHDJONq6zJP9QYOa6oSK X-Received: by 2002:a17:907:76c5:: with SMTP id kf5mr14059098ejc.526.1618691594516; Sat, 17 Apr 2021 13:33:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1618691594; cv=none; d=google.com; s=arc-20160816; b=HbB9do7jwZpGiRftKmUrTudt8MZ+kxVMSs8Rv9lCG9odemqtRUxORL6fZcqTNZTxeK Z+KPruTj2c0z7V7g6MOZBEB8i/6UR/aU8D/HoLrSbcHu1jT/XlmFNzQ193Mwvh2VrsGi 9qtHKsBdiEIfccYPdj71oi1PtgtYKFNl7LJW9mTjGpH/lh4R/5jIrIrbdAZlAHxKnrK4 o6a1y4wRWhpS4Q5hkwAREdRnORDOsgGhVB9GuPMjrp/8JTjrHWA66GL6fp3ObuSlwDb1 oWZTYN+nSIKva9mzJatL1jJbUb1NKQgUhoBv0wU/Kfv+MwJ40Sahkou1m2dLuAv2Y/Vg dIxA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date; bh=faiNAlU1sj0yNSFV6NE6SMgtcU9BWqL+SrLI6nIwSFc=; b=Y3g3FLpWv+IY2WE1WmOi1RLvxPaqmWdaKkmYc6vaQkXYHIsDKJcvitvXF+M2CXNCef zh2OGzXgjXCSVbCLRAFmOheKfT+4QV5vwcOvZ5KjuKozuOZ3FKhqsjiRIS08jqg0uk8z ypY0KyzGKOh871etaTZY0utnqcO8WINtNdBjdhu5O9MNysAPq/qniLGtPADZG3MlKev5 1FNNHTrWLpT1pLz7eS0z0Nbh+bcSlpczsf1XyRR7z6tiWoflAF3aYYRPA2Ofymgejgsu PH0MYDMFHJ/13ovAJVlfABUPrYZIWh/+RCNMFl895ICrQ3SuLM0n61rrDG225Cy9U+KR GW3A== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id w4si3231064edc.281.2021.04.17.13.32.48; Sat, 17 Apr 2021 13:33:14 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237014AbhDQUbV (ORCPT + 99 others); Sat, 17 Apr 2021 16:31:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40410 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236755AbhDQUbU (ORCPT ); Sat, 17 Apr 2021 16:31:20 -0400 Received: from zeniv-ca.linux.org.uk (zeniv-ca.linux.org.uk [IPv6:2607:5300:60:148a::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0F68EC061574 for ; Sat, 17 Apr 2021 13:30:54 -0700 (PDT) Received: from viro by zeniv-ca.linux.org.uk with local (Exim 4.94 #2 (Red Hat Linux)) id 1lXraU-0068dY-GZ; Sat, 17 Apr 2021 20:30:42 +0000 Date: Sat, 17 Apr 2021 20:30:42 +0000 From: Al Viro To: Linus Torvalds Cc: Eric Dumazet , Thomas Gleixner , linux-kernel , Eric Dumazet , Theodore Ts'o Subject: Re: [PATCH] x86/uaccess: small optimization in unsafe_copy_to_user() Message-ID: References: <20210416192413.1514419-1-eric.dumazet@gmail.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 [tytso Cc'd] On Sat, Apr 17, 2021 at 06:09:44PM +0000, Al Viro wrote: > > Al - fairly trivial patch applied, comments? > > Should be fine... FWIW, I've a patch in the same area, making those suckers > return bool. Seeing that they are only ever called via dir_emit(), dir_emit_dot() > and dir_emit_dotdot() and all of those return ->actor(...) == 0... > > Anyway, that'd be trivial to rebase on top of yours. Actually... looking through that patch now I've noticed something fishy: in 1f60fbe72749 ("ext4: allow readdir()'s of large empty directories to be interrupted" we had @@ -169,6 +169,8 @@ static int filldir(struct dir_context *ctx, const char *name, int namlen, } dirent = buf->previous; if (dirent) { + if (signal_pending(current)) + return -EINTR; and that thing is still there. However, it does *NOT* do what it might appear to be doing; it ends up with getdents() returning -EINVAL instead. What we need is buf->error = -EINTR; in addition to that return (in all 3 such places). Do you have any problems with the following delta? diff --git a/fs/readdir.c b/fs/readdir.c index 19434b3c982c..c742db935847 100644 --- a/fs/readdir.c +++ b/fs/readdir.c @@ -239,8 +239,10 @@ static int filldir(struct dir_context *ctx, const char *name, int namlen, return -EOVERFLOW; } prev_reclen = buf->prev_reclen; - if (prev_reclen && signal_pending(current)) + if (prev_reclen && signal_pending(current)) { + buf->error = -EINTR; return -EINTR; + } dirent = buf->current_dir; prev = (void __user *) dirent - prev_reclen; if (!user_write_access_begin(prev, reclen + prev_reclen)) @@ -321,8 +323,10 @@ static int filldir64(struct dir_context *ctx, const char *name, int namlen, if (reclen > buf->count) return -EINVAL; prev_reclen = buf->prev_reclen; - if (prev_reclen && signal_pending(current)) + if (prev_reclen && signal_pending(current)) { + buf->error = -EINTR; return -EINTR; + } dirent = buf->current_dir; prev = (void __user *)dirent - prev_reclen; if (!user_write_access_begin(prev, reclen + prev_reclen)) @@ -488,8 +492,10 @@ static int compat_filldir(struct dir_context *ctx, const char *name, int namlen, return -EOVERFLOW; } prev_reclen = buf->prev_reclen; - if (prev_reclen && signal_pending(current)) + if (prev_reclen && signal_pending(current)) { + buf->error = -EINTR; return -EINTR; + } dirent = buf->current_dir; prev = (void __user *) dirent - prev_reclen; if (!user_write_access_begin(prev, reclen + prev_reclen))