From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=74.125.229.9 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796418680; b=n4sRX37B6SanWeyRxyILcQATpnpptxoQIdijgWPvD0lbQASyrTE6ibO451z3JMn3fpY1 buIalX7CuFKhSCB9CWUvoDI7cRMWiRkarWBcpWR4VxU0Cg7XU9c+Xt/UT3C2RgD2gbRDT FvG5mGTqwEwFeqQy7FuNaO9F+LwlyvNwqYHFjBTAuf9m81sXYA++PJ8ayDA/aAbbI14D9 yHJVeB/tbwyWuw0jnhXtvq1lkQ88hPT2/IXc8htbnuSO+swPHyiAVOF7KD6FvxyUFzcvM kB0o1mm2VXR1FqfexWRUFVm0L8x6TmywKVgMOP5NsMfmKKtCH/XnSFVOxa7RoAJI/5A== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796418680; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: From:To:Cc:Subject:Date:Message-ID:X-Mailer:MIME-Version: Content-Transfer-Encoding; bh=fMwX2EiAEGLPoN3FeaoO2yeZCLgk53dAjL7e2Or6dzg=; b=oZFYgOmMRyPP6/HUEx+fqgTN5GWDe/WbkEhUJ5P4wZvJSKOMomAOldolQ+H8NeK3MiIz Bl/eg8KnEtCYteFg/xliXedhYrWRKFSwIHIHxH8sm/zTfg80F4wOMBzCFQiPZumVqCBe+ w83Ea0G22As7QW5iOPuEMcwqwcCMw0rYbYqgJ+r0TGkuPmN1j+HU4tZO1QUjXDjIf+4a+ p0HHFqgFn6WytRWgmSsoLe/dB8fZWFQtqm0HNy+3nfiGvWfSJXtNYlr92xV2YT6uQl59V E1gMU/sZxMtaSivRT6x5KykTcBiD2noiMKyufA7BPz6ek98+DJnwdzJ/MgxvR890oJA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=pdvIAf2t; arc=none smtp.remote-ip=74.125.229.9 Received: from mail-dy2-f9.google.com (mail-dy2-f9.google.com [74.125.229.9]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7F2C4606A322 for ; Fri, 4 Dec 2026 21:11:20 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 7F2C4606A322 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.a=rsa-sha256 header.s=20260707 header.b=pdvIAf2t Received: by mail-dy2-f9.google.com with SMTP id 5a478bee46e88-38754910f39so422675eec.1 for ; Fri, 04 Dec 2026 13:11:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796418680; x=1797023480; 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=fMwX2EiAEGLPoN3FeaoO2yeZCLgk53dAjL7e2Or6dzg=; b=pdvIAf2tY1RNRSuNQY9W9gfK1AYmu0DGWP1wyPelVByl8Nj+fXCNYT7dMeZcG/xx0S TWRAsRvh8BrWUX85SOlWRb/dhfmSXfrTXlNYgtuwDNIBhwaGG+K1BYzw7tKMBC0V7SmH o2h1bEF3v3OF1COLadoiEG4sK/aAifJLc39fou/nKMKByf3FU29oIjshQCVPg7OirjAG 75+GXKG/bbQfIvNwEkxtDHdNpsu4soPa+0vrpwPKBpPmiLtjhI72NB2PkBWmaMDzMzTe fgTvZ7RloWE4ta7gklPt15agNG3JOR34uHyjMclXlIvel4qV8eeOAsTtuxCLz8AALy2I MTmg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796418680; x=1797023480; 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=fMwX2EiAEGLPoN3FeaoO2yeZCLgk53dAjL7e2Or6dzg=; b=rT07dG8bVBL/j3rkLkVWTec7OKXRmhsCS5+uoPdstspZO+ovnhbnZYw+LMttaDwF5q ix8zv2PwZpsulw+04Pbx8+zT63U/7SZ9RywCEMbmPqm8kIjAMTVXV99OTATMPhgnbUeO dwB/o6PJHwyss4Eay53YbIhuJM6RKK8ft2hgDMi9ldldtn19fr5sXcnFpWUlM9eMCjR6 HGwLc+cWnheQB3u7WsgrN9sWHHahfLLeRS9x2HqLqXI+J5oK5TFC432ORBjquuxlpaXP SaXVpoosikOhhWGpsv3up7kwwjsl3W2aDAf6u6F3j5nIZJJ6ol90inqZVFQlwK+Hwxac i0SQ== X-Forwarded-Encrypted: i=1; AL+hErGRi2xwZRH414D08+5ZqN5+2FATNhzawG4h8IIoZYY4XMBEFWEwVxftC+GG8rxb7iO1VtbQ3Ph2o9wHuPA=@vger.kernel.org X-Gm-Message-State: APuU4Z/MYxo3o3KLVXlVgjwVuh2TXBPw5Ii4k5FyLxHO2/M00i0q0oRd DSSRNuO5AdEY2uvXb+uY3TaqjtBLXEqT1aJhPUIzocetUv63s1p8aLro X-Gm-Gg: AZFdTZfpQzQGD3y4GHKdrTjkX7jHhITdN1zgWQNk4jj2ow2CaAk3F5YkQyLY5VoTHoi F579Z6Nym/2ilk76qVHgvdrNq4sf6jJcwkTAnQ3bqfCg5aU+0ToB7xpPfH7ziAM+YgdmU5x9HhU 6+MoEQULvz8qOhXJADgfWf44d93aYQpBFTTvyt94HKkfR0+uoRfF5YJ69TBE05pG4Scig8wlsUX pu/SeW9Yy/jxdCy06g6rcOyf9aUbtIMZ5/22e9WmyGje2BgM/JhGre0UROPkhWaNqOfCEReAUyS oCOa2b22SF0jvp5Z5DK31eOWE1ZKiwL32YfuhcN9ndrpbliSSkk8Bf3XpIXpwsOiiEQUv5/aKMT Zw72SsA0yy63BbjtgAJMZbDNyQsYCgFpk7IF5gXMwL99aJsraA6cslUyfuX81oXHG+uprDsAiR4 s3sSWPsKILMkbt9j6AZ2LA/jejch0mtDTQqsMeSXWinavQky6tX39UwV/xZD58SDoLql81VMetj /6No54CMGHmpHSEnUHYa+FjsCoxLEbMoJ9kbGyQ0RIomDrcpV4yQosjJ7VBOl7sDuzS7hq4R+oc 6gF0DPF9YlwiHB0xmRBK/DtIvNSmwM4mSsF6WACsoe3h3lts1y6eamlKngz/ao26EBqJA1CKLbf kvtESUqjlEDy6CWeFbsY0w9bOPOO0hzvB8KT0jLMe X-Received: by 2002:a05:701b:2052:10b0:1b5:cae0:473c with SMTP id a92af1059eb24-1b5d712839fmr2712769c88.33.1796418679581; Fri, 04 Dec 2026 13:11:19 -0800 (PST) Received: from localhost.localdomain ([76.33.234.50]) by smtp.gmail.com with ESMTPSA id a92af1059eb24-1b5d64706d3sm9435838c88.13.2026.12.04.13.11.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Dec 2026 13:11:19 -0800 (PST) From: Hungyu Lin To: linkinjeon@kernel.org Cc: senozhatsky@chromium.org, tom@talpey.com, chenxiaosong@chenxiaosong.com, hyc.lee@gmail.com, lsahlber@redhat.com, icb@fastmail.org, linux-cifs@vger.kernel.org, linux-kernel@vger.kernel.org, dennylin0707@gmail.com Subject: [PATCH v3] ksmbd: refuse to open an append-only file for writing without O_APPEND Date: Fri, 4 Dec 2026 21:11:04 +0000 Message-ID: <20261204211104.93304-1-dennylin0707@gmail.com> X-Mailer: git-send-email 2.43.0 X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit smb2_open() opens the file with dentry_open(), which does not go through may_open(). inode_permission() refuses write access to an immutable inode, but nothing looks at S_APPEND. A client that has write permission on an append-only file can open it for writing and overwrite the data that is already there, which open(2) on the server and nfsd do not allow. Refuse the open like may_open() does, when the file is opened for writing without O_APPEND or the create disposition asks to overwrite it. smb2_create_open_flags() also selects O_WRONLY or O_RDWR for FILE_WRITE_EA and FILE_WRITE_ATTRIBUTES, so these opens are refused too. An open with MAXIMUM_ALLOWED is granted the write rights that the permission bits or the stored DACL allow and would be refused as well. Leave the write rights that the client did not ask for explicitly out of the access granted to such an open, so that it gets a handle for reading, and refuse the open when no access is left. The maximal access returned in the MxAc create context is not changed. Directories are left alone: an append-only directory still takes new entries. Fixes: e2f34481b24d ("cifsd: add server-side procedures for SMB3") Cc: stable@vger.kernel.org Signed-off-by: Hungyu Lin --- Changes in v3: - Refuse a MAXIMUM_ALLOWED open that is left with no access. With a stored DACL that grants only write rights the open used to succeed with an empty access mask. - Rebase on ksmbd-for-next. A POSIX open that asks for FILE_APPEND_DATA together with other write rights is opened with O_APPEND and keeps those rights. FSCTL_SET_SPARSE on such a handle appends zeroes to the file. That is the same without this patch, also for a file that is not append-only, and the data that is already in the file is not changed, so it is not handled here. v2: https://lore.kernel.org/linux-cifs/20261121182313.43201-1-dennylin0707@gmail.com/ Changes in v2: - Refuse every open for writing without O_APPEND, not only the ones that ask for FILE_WRITE_DATA or FILE_APPEND_DATA. A handle opened for FILE_WRITE_ATTRIBUTES could still reach kernel_write() through FSCTL_SET_SPARSE. - Refuse an overwrite disposition up front. The truncating ones used to fail in vfs_truncate() after the oplocks were broken, with STATUS_SHARING_VIOLATION. - Drop the write rights of a MAXIMUM_ALLOWED open in smb2_open() instead of ksmbd_vfs_query_maximal_access(), so that a file with a stored DACL is covered too and the MxAc reply stays as it is. - Keep the rights the client asked for next to MAXIMUM_ALLOWED. A POSIX open for MAXIMUM_ALLOWED | FILE_APPEND_DATA can append again, as reported by Ian Bridges. v1: https://lore.kernel.org/linux-cifs/20261120071553.28739-1-dennylin0707@gmail.com/ fs/smb/server/smb2pdu.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/fs/smb/server/smb2pdu.c b/fs/smb/server/smb2pdu.c index a7bf61a6fd6a..390deee31539 100644 --- a/fs/smb/server/smb2pdu.c +++ b/fs/smb/server/smb2pdu.c @@ -5168,6 +5168,18 @@ int smb2_open(struct ksmbd_work *work) maximal_access = daccess; } + if (req->DesiredAccess & FILE_MAXIMAL_ACCESS_LE && file_present && + IS_APPEND(d_inode(path.dentry)) && + !S_ISDIR(d_inode(path.dentry)->i_mode)) { + __le32 asked = smb_map_generic_desired_access(req->DesiredAccess); + + daccess &= ~(FILE_WRITE_DESIRE_ACCESS_LE & ~asked); + if (!daccess) { + rc = -EACCES; + goto err_out; + } + } + /* MAXIMUM_ALLOWED may not have granted the requested DELETE */ if (req->CreateOptions & FILE_DELETE_ON_CLOSE_LE && !(daccess & FILE_DELETE_LE)) { @@ -5262,6 +5274,19 @@ int smb2_open(struct ksmbd_work *work) goto err_out; } + if (IS_APPEND(d_inode(path.dentry)) && + !S_ISDIR(d_inode(path.dentry)->i_mode)) { + if ((open_flags & O_ACCMODE) != O_RDONLY && + !(open_flags & O_APPEND)) { + rc = -EACCES; + goto err_out; + } + if (open_flags & O_TRUNC) { + rc = -EACCES; + goto err_out; + } + } + rc = 0; filp = dentry_open(&path, open_flags, current_cred()); if (IS_ERR(filp)) { -- 2.43.0