From patchwork Tue Sep 20 13:20:43 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Namjae Jeon X-Patchwork-Id: 12982166 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E6365ECAAD8 for ; Tue, 20 Sep 2022 13:21:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229801AbiITNVB (ORCPT ); Tue, 20 Sep 2022 09:21:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57012 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230133AbiITNVB (ORCPT ); Tue, 20 Sep 2022 09:21:01 -0400 Received: from mail-pl1-f174.google.com (mail-pl1-f174.google.com [209.85.214.174]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4E90C3DBE8 for ; Tue, 20 Sep 2022 06:21:00 -0700 (PDT) Received: by mail-pl1-f174.google.com with SMTP id iw17so2393619plb.0 for ; Tue, 20 Sep 2022 06:21:00 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date; bh=OtTNvzDwdt8zM14tNoGDhevPuRdtk44YBNelmuHNpBI=; b=1ZS03eSXzjDw0GG3SsP4UMSnlMKjZ0w8rFma74NmSaCT48s5EiHrpblnNkWpb3eDNg OJ8/Y1+SU7kPsP9PBfgnnMYtyBvbI1Q8oHooMCMATcofrTnyOzsS4x2KkSwsyvNPizPr cpUTriePDfZWBzDa62HvZvqAAGDCnZXyR+5ld2Sty+g70Wh/yzc8hQNWlSmtuIPsYo7p 2r/YJLtNwDNbVCl/z6r330Q5ZCdvHxNe3sFWu9IRf+f6SgIFn7/UNUkNg4Co+hvm3wAj ow58H+Oy0PDsd16BDikXXw+6V/4VZ3/RHQOntxLnwEaURUupzZf4oqN+zPH2QlEhYoq2 O6XQ== X-Gm-Message-State: ACrzQf04Tg5frP+EOgOCvyCVpCgKWLO+QfUJppZFQ1oEqR+Wr7xJFM0k F5zfKf+TXE5dE06k54iq/aV2YQVaoOI= X-Google-Smtp-Source: AMsMyM7367ENU1ndc6eyPGliPbY6jgekspR//11nh8FW+mbKUSihr1y7ZnwdcM1LC4n7fUrWdiovYg== X-Received: by 2002:a17:90a:db04:b0:203:6731:caf8 with SMTP id g4-20020a17090adb0400b002036731caf8mr3988361pjv.190.1663680059504; Tue, 20 Sep 2022 06:20:59 -0700 (PDT) Received: from localhost.localdomain ([211.49.23.9]) by smtp.gmail.com with ESMTPSA id ix18-20020a170902f81200b001767f6f04efsm1360851plb.242.2022.09.20.06.20.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Sep 2022 06:20:58 -0700 (PDT) From: Namjae Jeon To: linux-cifs@vger.kernel.org Cc: smfrench@gmail.com, senozhatsky@chromium.org, tom@talpey.com, atteh.mailbox@gmail.com, Namjae Jeon Subject: [PATCH 1/3] ksmbd: change security id to the one samba used for posix extension Date: Tue, 20 Sep 2022 22:20:43 +0900 Message-Id: <20220920132045.5055-1-linkinjeon@kernel.org> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-cifs@vger.kernel.org Samba set SIDOWNER and SIDUNIX_GROUP in create posix context and set SIDUNIX_USER/GROUP in other sids for posix extension. This patch change security id to the one samba used. Signed-off-by: Namjae Jeon --- fs/ksmbd/oplock.c | 6 +++--- fs/ksmbd/smb2pdu.c | 4 ++-- fs/ksmbd/smb2pdu.h | 4 ++-- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/fs/ksmbd/oplock.c b/fs/ksmbd/oplock.c index 2e56dac1fa6e..c26f02086783 100644 --- a/fs/ksmbd/oplock.c +++ b/fs/ksmbd/oplock.c @@ -1616,7 +1616,7 @@ void create_posix_rsp_buf(char *cc, struct ksmbd_file *fp) memset(buf, 0, sizeof(struct create_posix_rsp)); buf->ccontext.DataOffset = cpu_to_le16(offsetof (struct create_posix_rsp, nlink)); - buf->ccontext.DataLength = cpu_to_le32(52); + buf->ccontext.DataLength = cpu_to_le32(56); buf->ccontext.NameOffset = cpu_to_le16(offsetof (struct create_posix_rsp, Name)); buf->ccontext.NameLength = cpu_to_le16(POSIX_CTXT_DATA_LEN); @@ -1642,9 +1642,9 @@ void create_posix_rsp_buf(char *cc, struct ksmbd_file *fp) buf->reparse_tag = cpu_to_le32(fp->volatile_id); buf->mode = cpu_to_le32(inode->i_mode); id_to_sid(from_kuid_munged(&init_user_ns, vfsuid_into_kuid(vfsuid)), - SIDNFS_USER, (struct smb_sid *)&buf->SidBuffer[0]); + SIDOWNER, (struct smb_sid *)&buf->SidBuffer[0]); id_to_sid(from_kgid_munged(&init_user_ns, vfsgid_into_kgid(vfsgid)), - SIDNFS_GROUP, (struct smb_sid *)&buf->SidBuffer[20]); + SIDUNIX_GROUP, (struct smb_sid *)&buf->SidBuffer[28]); } /* diff --git a/fs/ksmbd/smb2pdu.c b/fs/ksmbd/smb2pdu.c index f33a04e9e458..bc6c7ce17ea8 100644 --- a/fs/ksmbd/smb2pdu.c +++ b/fs/ksmbd/smb2pdu.c @@ -3573,9 +3573,9 @@ static int smb2_populate_readdir_entry(struct ksmbd_conn *conn, int info_level, if (d_info->hide_dot_file && d_info->name[0] == '.') posix_info->DosAttributes |= FILE_ATTRIBUTE_HIDDEN_LE; id_to_sid(from_kuid_munged(&init_user_ns, ksmbd_kstat->kstat->uid), - SIDNFS_USER, (struct smb_sid *)&posix_info->SidBuffer[0]); + SIDUNIX_USER, (struct smb_sid *)&posix_info->SidBuffer[0]); id_to_sid(from_kgid_munged(&init_user_ns, ksmbd_kstat->kstat->gid), - SIDNFS_GROUP, (struct smb_sid *)&posix_info->SidBuffer[20]); + SIDUNIX_GROUP, (struct smb_sid *)&posix_info->SidBuffer[16]); memcpy(posix_info->name, conv_name, conv_len); posix_info->name_len = cpu_to_le32(conv_len); posix_info->NextEntryOffset = cpu_to_le32(next_entry_offset); diff --git a/fs/ksmbd/smb2pdu.h b/fs/ksmbd/smb2pdu.h index af455278d005..32c525bf790a 100644 --- a/fs/ksmbd/smb2pdu.h +++ b/fs/ksmbd/smb2pdu.h @@ -158,7 +158,7 @@ struct create_posix_rsp { __le32 nlink; __le32 reparse_tag; __le32 mode; - u8 SidBuffer[40]; + u8 SidBuffer[44]; } __packed; struct smb2_buffer_desc_v1 { @@ -439,7 +439,7 @@ struct smb2_posix_info { __le32 HardLinks; __le32 ReparseTag; __le32 Mode; - u8 SidBuffer[40]; + u8 SidBuffer[32]; __le32 name_len; u8 name[1]; /* From patchwork Tue Sep 20 13:20:44 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Namjae Jeon X-Patchwork-Id: 12982167 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id BC265ECAAD8 for ; Tue, 20 Sep 2022 13:21:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229490AbiITNVG (ORCPT ); Tue, 20 Sep 2022 09:21:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57128 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230133AbiITNVE (ORCPT ); Tue, 20 Sep 2022 09:21:04 -0400 Received: from mail-pj1-f42.google.com (mail-pj1-f42.google.com [209.85.216.42]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8502E4B4B4 for ; Tue, 20 Sep 2022 06:21:03 -0700 (PDT) Received: by mail-pj1-f42.google.com with SMTP id s14-20020a17090a6e4e00b0020057c70943so10780429pjm.1 for ; Tue, 20 Sep 2022 06:21:03 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date; bh=t28g4ekicImW7p17MGbK+iOfJKtaRZ9e/vNICYRq/UY=; b=59j0YyegmhoKDyKX2ddotIedafFSjNLqN0sHUDOnrlMq63lrSOahCufTJ79zaXyKnM /6ARW/0OwEE+04z7/dMykk1OlUyEoszaYp6RZlmgXlcQoQFa6np2tjPDLCRhxN8c2OP7 0ttvyXwIqpE/JPVErl6pveZrYFHY+ErHRqeOpQPyL1CbFEdGhCihMS86m3TpnU+M+cBp cD04Q0MvLgcZIl+5xJftQHQMb1FG5FaX51ChMqFL7n5c/H9dsQ89J3E3RR48LzPCNjy/ KNfaltSDWgEleE+a+bg7YpPKJQ/CqXLF6JqVvV65/ejAVAr0n1iBfpNUK7f8+y2s8TGV fJCg== X-Gm-Message-State: ACrzQf0fmtx6UJ/4vsuSifHVZkrMOnjrWRAZQlNS8jN/mxsvChX69p+g E62ZAiuNiM4soZsPrxQPkmasWZ7eFD4= X-Google-Smtp-Source: AMsMyM4e8BHXh38dCsj6a5mkamK0dwioota/S9M+DJq6Ngv6lSO+ttwgi9wFv2KZ5IxzVXJgHS+47Q== X-Received: by 2002:a17:902:c104:b0:176:e2fa:2154 with SMTP id 4-20020a170902c10400b00176e2fa2154mr4882624pli.98.1663680062700; Tue, 20 Sep 2022 06:21:02 -0700 (PDT) Received: from localhost.localdomain ([211.49.23.9]) by smtp.gmail.com with ESMTPSA id ix18-20020a170902f81200b001767f6f04efsm1360851plb.242.2022.09.20.06.21.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Sep 2022 06:21:02 -0700 (PDT) From: Namjae Jeon To: linux-cifs@vger.kernel.org Cc: smfrench@gmail.com, senozhatsky@chromium.org, tom@talpey.com, atteh.mailbox@gmail.com, Namjae Jeon Subject: [PATCH 2/3] ksmbd: set only file permisson to mode for posix extension Date: Tue, 20 Sep 2022 22:20:44 +0900 Message-Id: <20220920132045.5055-2-linkinjeon@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220920132045.5055-1-linkinjeon@kernel.org> References: <20220920132045.5055-1-linkinjeon@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-cifs@vger.kernel.org Set only file permisson to mode for posix extension like samba. Signed-off-by: Namjae Jeon Acked-by: Tom Talpey --- fs/ksmbd/oplock.c | 2 +- fs/ksmbd/smb2pdu.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/fs/ksmbd/oplock.c b/fs/ksmbd/oplock.c index c26f02086783..9bfd1ef6debd 100644 --- a/fs/ksmbd/oplock.c +++ b/fs/ksmbd/oplock.c @@ -1640,7 +1640,7 @@ void create_posix_rsp_buf(char *cc, struct ksmbd_file *fp) buf->nlink = cpu_to_le32(inode->i_nlink); buf->reparse_tag = cpu_to_le32(fp->volatile_id); - buf->mode = cpu_to_le32(inode->i_mode); + buf->mode = cpu_to_le32(inode->i_mode & 0777); id_to_sid(from_kuid_munged(&init_user_ns, vfsuid_into_kuid(vfsuid)), SIDOWNER, (struct smb_sid *)&buf->SidBuffer[0]); id_to_sid(from_kgid_munged(&init_user_ns, vfsgid_into_kgid(vfsgid)), diff --git a/fs/ksmbd/smb2pdu.c b/fs/ksmbd/smb2pdu.c index bc6c7ce17ea8..5c797cc09494 100644 --- a/fs/ksmbd/smb2pdu.c +++ b/fs/ksmbd/smb2pdu.c @@ -3565,7 +3565,7 @@ static int smb2_populate_readdir_entry(struct ksmbd_conn *conn, int info_level, posix_info->AllocationSize = cpu_to_le64(ksmbd_kstat->kstat->blocks << 9); posix_info->DeviceId = cpu_to_le32(ksmbd_kstat->kstat->rdev); posix_info->HardLinks = cpu_to_le32(ksmbd_kstat->kstat->nlink); - posix_info->Mode = cpu_to_le32(ksmbd_kstat->kstat->mode); + posix_info->Mode = cpu_to_le32(ksmbd_kstat->kstat->mode & 0777); posix_info->Inode = cpu_to_le64(ksmbd_kstat->kstat->ino); posix_info->DosAttributes = S_ISDIR(ksmbd_kstat->kstat->mode) ? @@ -4732,7 +4732,7 @@ static int find_file_posix_info(struct smb2_query_info_rsp *rsp, file_info->EndOfFile = cpu_to_le64(inode->i_size); file_info->AllocationSize = cpu_to_le64(inode->i_blocks << 9); file_info->HardLinks = cpu_to_le32(inode->i_nlink); - file_info->Mode = cpu_to_le32(inode->i_mode); + file_info->Mode = cpu_to_le32(inode->i_mode & 0777); file_info->DeviceId = cpu_to_le32(inode->i_rdev); rsp->OutputBufferLength = cpu_to_le32(sizeof(struct smb311_posix_qinfo)); From patchwork Tue Sep 20 13:20:45 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Namjae Jeon X-Patchwork-Id: 12982168 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 62E12C54EE9 for ; Tue, 20 Sep 2022 13:21:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230133AbiITNVJ (ORCPT ); Tue, 20 Sep 2022 09:21:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57212 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230238AbiITNVI (ORCPT ); Tue, 20 Sep 2022 09:21:08 -0400 Received: from mail-pl1-f172.google.com (mail-pl1-f172.google.com [209.85.214.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 53A7B4B4B4 for ; Tue, 20 Sep 2022 06:21:06 -0700 (PDT) Received: by mail-pl1-f172.google.com with SMTP id f23so2345410plr.6 for ; Tue, 20 Sep 2022 06:21:06 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date; bh=1aawr18KpuWrUUAhjpSuzcNQ554sgmWs/WMiARBkcqs=; b=2RPOluo3HVQ/f3yHNAfNWj6nvwdGWurxAopqL8QOc5P9cNPhkGzjmF2+aBxkyyThZy 9aTCYOX8WfLKs5EWV3Whf93c8hl8DeVNm0vdyWIwH8H3LspQBp1f5J4VMHuHtvSO1jer buXpkccNzI8PVNRU/OoqyIiU2RmyTykAw5EzFFed8B/kldgVELrGbOquwefZREKcHIKK rzqYNccky35w/LSwrK611mjBpfrZ3P+Y/cgWrWzZLyNhFkH/6BR/Ekk6x5HsbYUNurOy zIraxvVCVkeL/3UTvdxsNL+4OGC65a5a+XSO+O23vQmFSSUuP9x2BCtCzDaQv17x2Brw 0U8w== X-Gm-Message-State: ACrzQf2Jw4dGGUN5CeOonupoC0AtTTFNJZbyohkbcjRXYaCi110LTR7V 27z4M08ZOa89lzJ32yaO114d6N7dmvY= X-Google-Smtp-Source: AMsMyM41e/co2s79H6hGflxZuuMfhoazU+IDqoC8ir6l6E++ICM7+LSNDZl9ia6I/OZjMqLVB8/qpg== X-Received: by 2002:a17:902:784d:b0:178:6946:3ff7 with SMTP id e13-20020a170902784d00b0017869463ff7mr4798357pln.133.1663680065582; Tue, 20 Sep 2022 06:21:05 -0700 (PDT) Received: from localhost.localdomain ([211.49.23.9]) by smtp.gmail.com with ESMTPSA id ix18-20020a170902f81200b001767f6f04efsm1360851plb.242.2022.09.20.06.21.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Sep 2022 06:21:05 -0700 (PDT) From: Namjae Jeon To: linux-cifs@vger.kernel.org Cc: smfrench@gmail.com, senozhatsky@chromium.org, tom@talpey.com, atteh.mailbox@gmail.com, Namjae Jeon Subject: [PATCH 3/3] ksmbd: fill sids in SMB_FIND_FILE_POSIX_INFO response Date: Tue, 20 Sep 2022 22:20:45 +0900 Message-Id: <20220920132045.5055-3-linkinjeon@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220920132045.5055-1-linkinjeon@kernel.org> References: <20220920132045.5055-1-linkinjeon@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-cifs@vger.kernel.org This patch fill missing sids in SMB_FIND_FILE_POSIX_INFO response. Signed-off-by: Namjae Jeon --- fs/ksmbd/smb2pdu.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/fs/ksmbd/smb2pdu.c b/fs/ksmbd/smb2pdu.c index 5c797cc09494..9dd6033bc4de 100644 --- a/fs/ksmbd/smb2pdu.c +++ b/fs/ksmbd/smb2pdu.c @@ -4717,6 +4717,9 @@ static int find_file_posix_info(struct smb2_query_info_rsp *rsp, { struct smb311_posix_qinfo *file_info; struct inode *inode = file_inode(fp->filp); + struct user_namespace *user_ns = file_mnt_user_ns(fp->filp); + vfsuid_t vfsuid = i_uid_into_vfsuid(user_ns, inode); + vfsgid_t vfsgid = i_gid_into_vfsgid(user_ns, inode); u64 time; file_info = (struct smb311_posix_qinfo *)rsp->Buffer; @@ -4734,9 +4737,15 @@ static int find_file_posix_info(struct smb2_query_info_rsp *rsp, file_info->HardLinks = cpu_to_le32(inode->i_nlink); file_info->Mode = cpu_to_le32(inode->i_mode & 0777); file_info->DeviceId = cpu_to_le32(inode->i_rdev); + + id_to_sid(from_kuid_munged(&init_user_ns, vfsuid_into_kuid(vfsuid)), + SIDUNIX_USER, (struct smb_sid *)&file_info->Sids[0]); + id_to_sid(from_kgid_munged(&init_user_ns, vfsgid_into_kgid(vfsgid)), + SIDUNIX_GROUP, (struct smb_sid *)&file_info->Sids[16]); + rsp->OutputBufferLength = - cpu_to_le32(sizeof(struct smb311_posix_qinfo)); - inc_rfc1001_len(rsp_org, sizeof(struct smb311_posix_qinfo)); + cpu_to_le32(sizeof(struct smb311_posix_qinfo) + 32); + inc_rfc1001_len(rsp_org, sizeof(struct smb311_posix_qinfo) + 32); return 0; } @@ -4858,7 +4867,7 @@ static int smb2_get_info_file(struct ksmbd_work *work, rc = -EOPNOTSUPP; } else { rc = find_file_posix_info(rsp, fp, work->response_buf); - file_infoclass_size = sizeof(struct smb311_posix_qinfo); + file_infoclass_size = sizeof(struct smb311_posix_qinfo) + 32; } break; default: