From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pf1-f174.google.com (mail-pf1-f174.google.com [209.85.210.174]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3DF6D383C7C for ; Wed, 24 Jun 2026 20:13:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.174 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782332031; cv=none; b=ccDzs4PefqRNwi8t208vqs4BNSrjwsB2TNBwHn42/+pFrSBrm7gVJVk6xF6f5XPR4f3iHvc+CK/HSQrxDpJf0Z/lmzVaitwD9lNFmMtqEJX8sT/QDCxArd4TKlo6F086BhNaN18RwlAiq44i1/MaPmk2ghKUzKSmgZ2p4YrsYZM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782332031; c=relaxed/simple; bh=xI5xcvp5mGEQ7XhRqOY4Tv6Va2uYix/X6g+VU8h4FpU=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=i5PiwJnBJ5LyVG9Cdd/1isp5lYzsd3d/aVRCnMM05AKIOt5i2SZUigqov20OKubzo1urkNqOo8cY/BgBjeA5k/SVufw6SikPeVeJpUJqAZ/D+sKFXL8GkPQmYynsPXLQEw6DDbP3x+TnfuCIXQegsqW2Ku0DS1LKr/TbCfny5Z8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=sNkOX/23; arc=none smtp.client-ip=209.85.210.174 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="sNkOX/23" Received: by mail-pf1-f174.google.com with SMTP id d2e1a72fcca58-84537d04408so206293b3a.0 for ; Wed, 24 Jun 2026 13:13:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1782332028; x=1782936828; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to:content-type; bh=tqqyVxYSR69pT9ofMMz2pm4tMEW2deyHKj8QeIUn/cY=; b=sNkOX/237LIGYDxOoMqrzZy4KeS34l/KCgV4CmjjWGFY7Mduk1HNKMzLPoNNELZVuh ppLGazDLcUKAFm/4FuewN0DC8fEoW0+FO599TPnmDUiF8txP16myYCSkNMGRSSdsLYCZ 0TH1e/DzLOIvLW2m2fFMaAJGUJofr1RMLoIcBIDkOVKigUtBrEbRuKwbVOivdtsj9SKK velPx7oct8n8CCg3456mtgabVefhCcCZXb55WZjRHsMUPZb1yD1lU24FGTdcd+BtBpsP ztyMx0suJPupsCyyNWf4Dh4ndDwsd8+Kl8nCqz7UJ9CQ8THFZp3XpLaCDMI0Fs7CFB6h OhlA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1782332028; x=1782936828; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=tqqyVxYSR69pT9ofMMz2pm4tMEW2deyHKj8QeIUn/cY=; b=bwWA7D/oqNikhljFHQmwWSo2xd6RtKssqv2+beoAoa3DoJxmPUYGC9c6+JNmIAymR0 yUNVHVXSQjHE2YoHJXbCleQlHy/5yRt+sVKrqi+BPdQ/MNBIzmfbe3GqcB9VTcV9CneZ PI8RFztrBq1gKtV8FiMzN4/OerrSTrPXJPuc30TTsTL3qOVvSAqPO+lmG/vFiFCwU5vF RO5FYmB2uS4pOLA+hrvRrlidvZ+kmlPtfab33r3u9sxB4+SVvvIOc7lhpY565DjoP6+F wRiHTirQUiPI5yYxADBw62CoelVGGMXg29Fy0gJ48G83WKnxNIvPaPZZaA0x/KOD8QT7 Jbow== X-Forwarded-Encrypted: i=1; AHgh+Rp9r9/BCrAO3ql4EGeQlVrDNp50tmvlV7r/Ybj/Q7zumk9ORVE5zEr2YFxGNUgoPjYskr7dhSojBevazE0=@vger.kernel.org X-Gm-Message-State: AOJu0YxiSdioaWYx34R3YSsJiY+JZBxhIgad9+6pq1yqIc2QAFgwiAQG C0FzzO8Pu3h4meGAjV7ifoY94VLGYvxl1rZjsrpvV5SZi7xSC19br0VB X-Gm-Gg: AfdE7ck1XwUXotfNGDaUi/JNqbIrflXFflZyCrzkeRLCJ8IseJpPKoFi1W1ys/G7WqU eggWC9NxmaboJct8uB9xHCMSRfyckRSzQWdXuctAdiUZK+VSJrLNCF8FDQwM9k/su46Ci1UO/WN si7droFlAjL50YN5JbF9a7aFVeCgFU50nblBAQDmvDC3ceMzUUKnk1CFlDXmdAlZPj3vyBfXkVS L4B8vtZj3GwXZJ/lXFQ405BnXdHjUlBrppVR0t9sWvULXvzOzllq50zUXGdDD4E3/pOv/3mAtXe ZWugK6yAbwz822LWbuHaJcIJt+K3vB1fLFLoasC0Oq2Zq36UvIUYYBe96fQeduVUW1EpcJFlGCo 1i4QKVeynii44uQMHfXk196KTqS5vce8qAzItB83EHsywAb9BPaqup6YRuIlAm2v2vGJGAiek0e G1j/LxOrF6ltcO X-Received: by 2002:a17:902:d4d0:b0:2c0:b359:99c1 with SMTP id d9443c01a7336-2c7bf10e092mr50660025ad.2.1782332028375; Wed, 24 Jun 2026 13:13:48 -0700 (PDT) Received: from pop-os.. ([114.4.214.149]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2c7f63d245asm4777925ad.58.2026.06.24.13.13.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Jun 2026 13:13:47 -0700 (PDT) From: Yudistira Putra To: David Howells Cc: netfs@lists.linux.dev, linux-kernel@vger.kernel.org, Yudistira Putra Subject: [PATCH] cachefiles: reject copen before OPEN delivery completes Date: Wed, 24 Jun 2026 16:11:24 -0400 Message-ID: <20260624201124.120004-1-pyudistira519@gmail.com> X-Mailer: git-send-email 2.43.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit cachefiles_ondemand_daemon_read() creates an anonymous fd for CACHEFILES_OP_OPEN before copying the OPEN message to userspace. If copy_to_user() fails after a partial copy, userspace may already have observed the OPEN message id. A racing copen can then complete the OPEN request before the failed-read cleanup finishes. This allows the OPEN waiter to observe success even though daemon-side OPEN message delivery failed. Record when the OPEN message has actually been delivered and the anonymous fd has been installed. Reject copen before that point, so a partially copied failed read cannot complete the OPEN request successfully. A local reproducer that faults the daemon read buffer previously showed COPEN_FAST ok=1. With this change, the same reproducer reaches the failed OPEN delivery path but copen is rejected consistently: Trials: 10 READ EFAULT: 10 COPEN_FAST ok=0: 10 COPEN_FAST ok=1: 0 WATCHDOG_TIMEOUT: 0 Signed-off-by: Yudistira Putra --- fs/cachefiles/internal.h | 1 + fs/cachefiles/ondemand.c | 12 ++++++++++++ 2 files changed, 13 insertions(+) diff --git a/fs/cachefiles/internal.h b/fs/cachefiles/internal.h index b62cd3e..72fa413 100644 --- a/fs/cachefiles/internal.h +++ b/fs/cachefiles/internal.h @@ -143,6 +143,7 @@ struct cachefiles_req { struct completion done; refcount_t ref; int error; + bool open_msg_delivered; struct cachefiles_msg msg; }; diff --git a/fs/cachefiles/ondemand.c b/fs/cachefiles/ondemand.c index 0849eaf..16136ff 100644 --- a/fs/cachefiles/ondemand.c +++ b/fs/cachefiles/ondemand.c @@ -196,6 +196,17 @@ int cachefiles_ondemand_copen(struct cachefiles_cache *cache, char *args) xa_unlock(&cache->reqs); return -EINVAL; } + + /* + * The OPEN request must not be completed by copen until the + * daemon_read side has successfully delivered the OPEN message and + * installed the anonymous fd. Otherwise a daemon can use a partially + * copied message from a failed read to complete the request. + */ + if (!READ_ONCE(req->open_msg_delivered)) { + xa_unlock(&cache->reqs); + return -EAGAIN; + } xas_store(&xas, NULL); xa_unlock(&cache->reqs); @@ -469,6 +480,7 @@ ssize_t cachefiles_ondemand_daemon_read(struct cachefiles_cache *cache, goto out; } fd_install(anon_file.fd, anon_file.file); + WRITE_ONCE(req->open_msg_delivered, true); } out: cachefiles_put_object(req->object, cachefiles_obj_put_read_req); -- 2.43.0