Received: by 2002:ab2:6816:0:b0:1f9:5764:f03e with SMTP id t22csp3086001lqo; Tue, 21 May 2024 06:36:45 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUuN0hA0afwhnyTcWrgDCNMm1SxOCoME1i4hwieIlaOP1IN9LHiEdGenqaCsI2IAeJYtvD3vP5UzJjiMAPpT47uVGywt+mn+RqYM6uhhQ== X-Google-Smtp-Source: AGHT+IF8o3RrBojazdGhgkYd0Pcb6tACOY6lQD8G/BIPbRgrOo/Nsj/ZGhW00LnqcR2104cJuBMw X-Received: by 2002:a05:6a20:9f4a:b0:1b0:278e:34a6 with SMTP id adf61e73a8af0-1b0278e367dmr13802534637.49.1716298604607; Tue, 21 May 2024 06:36:44 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1716298604; cv=pass; d=google.com; s=arc-20160816; b=tuiTKy5xGpN1LwFCwHcYzHGg9PHoewWmqdQqDodaP2qffRq8ZD7KWoZqEgzWupohAo Vi+uza2J8Y+JgAZIABk7g73gRN5tPRagJQn78hpyhto8VFlB3ULTNNaWVTMhch3mZMhg KlbgHCWvbn9HAV/fbUhJo1qFcuSG+UQr3LnFJs0X3WGK0AznYN0Boky3XtADc1omsYGT gHIZU9qavWFBzfEv8xcF/vrPFqT15FePv7WGIv9rz223/zC2ZPvN+kBMmJwevcG1Bpqq 1NMy1Pe0F5xMiYiN/jnfNG693aaVWJfuV373ENVp0qJE3cO2I9BmKkdvtPVTyW4OUz7U OTqg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=message-id:date:content-transfer-encoding:content-id:mime-version :list-unsubscribe:list-subscribe:list-id:precedence:subject:cc:to :from:organization:dkim-signature; bh=tQ93YOLA+ZarT84k8WHzLRGgN4pa3R9T2oT8BE3LSw4=; fh=kK1kOpwj8D/QOMyoKXoEgPM4lZ3yw6g38cSiJ+f+bEk=; b=EfaJeVOIDHhpbSO2ns2nEi19egoTHyOxZ+oFwDc8ykHbtgjJqJux4MFOdvrtTG3Erx ArXQhhHuLXmkVMb+9yx5xbgx+oDueqzBFpvrWBiSY+ou9WGYf8sK9Ve7ED1uXSp+5NkQ uFvlA7Dj3mDJmFgMujFQnsjDsG+6s+p3ZRyru2QEnZ4fpqORtgHzLSyG8tYAMr4wDex2 C/5zcNX+TZjdbdlgqdxNlkju3ffjDYRpwHTTGydyTgR6TOK5LLvkNrN/sdw2JL9yRJuI VTcGgGq7CfemOP2c6ULhvzvyQ/+WD9AlS+WqBb+mvkJPRhln8Hxhh7dkRiBqwb5XMwum FpXg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="U1/1cCNh"; arc=pass (i=1 spf=pass spfdomain=redhat.com dkim=pass dkdomain=redhat.com dmarc=pass fromdomain=redhat.com); spf=pass (google.com: domain of linux-kernel+bounces-185019-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-185019-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. [139.178.88.99]) by mx.google.com with ESMTPS id d9443c01a7336-1f307badcbesi24840905ad.326.2024.05.21.06.36.44 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 May 2024 06:36:44 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-185019-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="U1/1cCNh"; arc=pass (i=1 spf=pass spfdomain=redhat.com dkim=pass dkdomain=redhat.com dmarc=pass fromdomain=redhat.com); spf=pass (google.com: domain of linux-kernel+bounces-185019-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-185019-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 449FE283E9A for ; Tue, 21 May 2024 13:36:44 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 852717EF0A; Tue, 21 May 2024 13:36:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="U1/1cCNh" 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 2B69E6E602 for ; Tue, 21 May 2024 13:36:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716298596; cv=none; b=KV7oTW5OoNe2HW1l8sAFeSMts8A1t/3snKg5nlGBBEQvxZuuKBIyhZOefPYQFxmHIOg2Ad33loL6SHSOFmUIUNo2jFbRoTdFMGx83CE6WTIUkFfAMh2gQDhuEs/dqdGX/PlKOibNpJH71T0E4em2nqBrA3JnlsUQi2oXSyc+exw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716298596; c=relaxed/simple; bh=wooh8rG/Ageclm++Zoo32v4gpqwOYEvywXeGxlbSL1c=; h=From:To:cc:Subject:MIME-Version:Content-Type:Date:Message-ID; b=LlmEgdMXfQrpW1On8xI+A1fHtmo0LHWpilgEnm9TbeazajXPZS9b4kwV9yrloU1/iWPPrfW6XNKKIxvf4eP27Qsi6aYInm/OVrTwwtOf1gpCWM9xS+rPd5C0PwE2ahJJOY9A/GpSC2RSYKAjekfseWltMPe5RhccW3EdHsWwyn8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=U1/1cCNh; arc=none smtp.client-ip=170.10.129.124 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=1716298594; 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=tQ93YOLA+ZarT84k8WHzLRGgN4pa3R9T2oT8BE3LSw4=; b=U1/1cCNhueMTsclJTn9V+sm3pyiBrO+XRhsFKk7Ow8GF+euzA88wbCviPfIulfasawm3BM V7xxNSPLwpDv2U8L5CNXBOr6/F4AScARiHRQHaY0TPJB4auuI1Yi0tkcZtsWx5Kga6x35A YmJVqVB0LtkXtsZfuIB8XzlFA0TyPkw= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-85-IRM4g2I6Pu-_TFIqfGEhVw-1; Tue, 21 May 2024 09:36:30 -0400 X-MC-Unique: IRM4g2I6Pu-_TFIqfGEhVw-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (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 D422818188A1; Tue, 21 May 2024 13:36:29 +0000 (UTC) Received: from warthog.procyon.org.uk (unknown [10.42.28.20]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6CA4E200A35C; Tue, 21 May 2024 13:36:28 +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: Steve French cc: dhowells@redhat.com, Jeff Layton , Enzo Matsumiya , Christian Brauner , netfs@lists.linux.dev, v9fs@lists.linux.dev, linux-afs@lists.infradead.org, linux-cifs@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] netfs: Fix AIO error handling when doing write-through Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <295051.1716298587.1@warthog.procyon.org.uk> Content-Transfer-Encoding: quoted-printable Date: Tue, 21 May 2024 14:36:27 +0100 Message-ID: <295052.1716298587@warthog.procyon.org.uk> X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.6 If an error occurs whilst we're doing an AIO write in write-through mode, we may end up calling ->ki_complete() *and* returning an error from ->write_iter(). This can result in either a UAF (the ->ki_complete() func pointer may get overwritten, for example) or a refcount underflow in io_submit() as ->ki_complete is called twice. Fix this by making netfs_end_writethrough() - and thus netfs_perform_write() - unconditionally return -EIOCBQUEUED if we're doing an AIO write and wait for completion if we're not. Fixes: 288ace2f57c9 ("netfs: New writeback implementation") Signed-off-by: David Howells cc: Jeff Layton cc: Enzo Matsumiya cc: netfs@lists.linux.dev cc: v9fs@lists.linux.dev cc: linux-afs@lists.infradead.org cc: linux-cifs@vger.kernel.org cc: linux-fsdevel@vger.kernel.org --- fs/netfs/write_issue.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/fs/netfs/write_issue.c b/fs/netfs/write_issue.c index e190043bc0da..acbfd1f5ee9d 100644 --- a/fs/netfs/write_issue.c +++ b/fs/netfs/write_issue.c @@ -636,7 +636,12 @@ int netfs_end_writethrough(struct netfs_io_request *w= req, struct writeback_contr = mutex_unlock(&ictx->wb_lock); = - ret =3D wreq->error; + if (wreq->iocb) { + ret =3D -EIOCBQUEUED; + } else { + wait_on_bit(&wreq->flags, NETFS_RREQ_IN_PROGRESS, TASK_UNINTERRUPTIBLE)= ; + ret =3D wreq->error; + } netfs_put_request(wreq, false, netfs_rreq_trace_put_return); return ret; }