Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Android phones and TV boxes using Android with Kodi issue #476

Open
flood404 opened this issue Feb 24, 2024 · 67 comments
Open

Android phones and TV boxes using Android with Kodi issue #476

flood404 opened this issue Feb 24, 2024 · 67 comments

Comments

@flood404
Copy link

Running DD-WRT with this ksmbd built in. Running the latest release ksmbd according to the DD-WRT developer.

Anytime I access shares with Kodi latest version Kodi will say software caused connection to close. Or connection refused.

In the DD-WRT logs it spams this when trying to access the shared drives.

ksmbd: error while processing smb2 query dir rc = -22

This issue isn't affecting any systems running WIndows or Linux.

@namjaejeon
Copy link
Owner

Can you reproduce it with ksmbd github or ksmbd in linux-kernel ?

@flood404
Copy link
Author

I am not sure how to do any of that or compiling my own stuff I never done any of that. All I know is the DD-wrt Developer did this here.

https://svn.dd-wrt.com/changeset/54983

@namjaejeon
Copy link
Owner

When I have tested(movie play) using kodi app on ubuntu, there is no problem.
Can you explain how to reproduce this issue at detail ?
And what is local filesystem of share directory ?

@namjaejeon
Copy link
Owner

As I know, ksmbd in dd-wrt is different with github ksmbd source(https://github.com/namjaejeon/ksmbd).
I have tested github ksmbd, it is not ksmbd of dd-wrt.

@flood404
Copy link
Author

The issue comes up with Android versions of Kodi. Android based phones and TV boxes with Android on them. Windows Kodi and Linux Kodi is fine. It may just be an Android issue I should be asking on Kodi forum.

In DD-WRT the drives with the files are shared as Public and also tried username and password with samba protocols set to 2.0 and 3 they were accessed from Kodi at smb://192.168.1.1

The drives are formatted in EXT4 not NTFS.

@namjaejeon
Copy link
Owner

Okay, I will try to reproduce it using Android Kodi.

@namjaejeon
Copy link
Owner

I have installed and tested kodi app on android phone. It work fine to me.
Can you check mainline ksmbd or github ksmbd instead of dd-wrt ksmbd ?

@flood404
Copy link
Author

flood404 commented Mar 3, 2024

I am not a guru with doing this. I don't even know how to replace/swap or compile this. I am going to assume it's a DD-WRT issue since its most likely modified to run in DD-WRT. Your name was listed for the ksmbd part of it in the system logs. The sure way to duplicate this. Is to run dd-wrt on a spare PC or Hard drive and connect Android or Linux box to it. Kodi isn't needed. It even shows up trying to browse shares in Linux or and Android file manager with similar messages.

@namjaejeon
Copy link
Owner

there is only one I can help you now. Can you send me wireshark(or tcpdump) file when capturing packets on problem situation ?

@namjaejeon
Copy link
Owner

As I know, ksmbd in dd-wrt is different with mainline. So the latest MacOS can not connect with ksmbd in dd-wrt, but there is no issue with mainlin ksmbd.

@flood404
Copy link
Author

flood404 commented Mar 8, 2024

Im going to close this. I believe its a DD-WRT specific issue.

@namjaejeon
Copy link
Owner

How do you know if it is dd-wrt issue ?

@cyayon
Copy link

cyayon commented Mar 13, 2024

Hi,

I think I have the same issue with vanilla linux kernel > 6.6.10 (or near this version). Windows and MacOS clients do not have the issue. I had the issue with iOS applications (infuse - a kodi like for iOS/MacOS).

I upgraded to 6.7.6, 6.7.8, 6.7.9, same issue.
Then I upgraded to ksmbd 3.4.9 (linux kernel seems to use ksmbd 3.4.2) with dkms, the issue is solved.

Conclusion : there is an issue with 3.4.2 ksmbd included since the vanilla kernel > 6.6.10 (or near this version). To workaround the issue, you have to upgrade ksmbd 3.4.9 (I only tried the latest ksmbd). The issue seems to be related to some clients only.

@namjaejeon
Copy link
Owner

@cyayon Thanks for your comment.

@flood404
Copy link
Author

So it is a DD-WRT issue for using a older version then. Sebastian Gottschall should be notified about this who makes DD-WRT to update to the 3.4.9.

@cyayon
Copy link

cyayon commented Mar 18, 2024

Hi,
Please note that kernel 6.8.x vanilla always include ksmbd version 3.4.2...

@namjaejeon
Copy link
Owner

@cyayon I will remove ksmbd version in linux mainline. the version is not needed for mainline kernel.

@cyayon
Copy link

cyayon commented Mar 18, 2024

Hi,
Does it mean that we have to use dkms to use ksmbd ? Like openzfs ?

@namjaejeon
Copy link
Owner

namjaejeon commented Mar 18, 2024

You have understand removing ksmbd module in mainline ? I an trying just remove module version from ksmbd.
Since we have a Linux version, there is no reason to have a separate ksmbd version in mainline. Look at nfs. It do not have a separate version number.

@cyayon
Copy link

cyayon commented Mar 18, 2024

sorry, you're right :)
How differ the included ksmbd version from the last stable 3.4.9 ?
Why the current issue is solved by upgrading ksmbd to the last 3.4.9 (and using dkms) ?
thanks

@namjaejeon
Copy link
Owner

mainline ksmbd is same with github ksmbd. dd-wrt use old source. if dd-write use the latest github ksmbd or ksmbd in mainline kernel, problem will not happen.

@cyayon
Copy link

cyayon commented Mar 18, 2024

Sorry, but I encounter an issue with mainline kernel (on archlinux), not dd-wrt.
It seems to be a disconnect issue with certain smb client. See my post 5 days ago please.

thanks

@namjaejeon
Copy link
Owner

Please share a link for this. I can not find it.

@cyayon
Copy link

cyayon commented Mar 18, 2024

#476 (comment)

@namjaejeon
Copy link
Owner

6.7 version is not stable version. Please don't use 6.7.x kernel version. and I have recently updated ksmbd in the latest 6.6.x kernel. have you tried the latest 6.6.22 version ?

@cyayon
Copy link

cyayon commented Mar 18, 2024

I have tried 6.6.20 (latest LTS when I had the issue after upgrading archlinux - from 6.6.x to 6.7.x). The issue appears > 6.6.10 (my last know good kernel version).
Since this day, I had to use ksmbd 3.4.9 via dkms with latest mainline kernel version (marked as stable on kernel.org).

@namjaejeon
Copy link
Owner

How can I reproduce it ? I should play infuse application in MacOS ? Can I reproduce your problem with linux client or windows client ?

@namjaejeon
Copy link
Owner

and I have tested kodi app against both ksmbd in linux kernel and dkms ksmbd. both ones doesn't have issue with kodi.

@namjaejeon
Copy link
Owner

Then I upgraded to ksmbd 3.4.9 (linux kernel seems to use ksmbd 3.4.2) with dkms, the issue is solved.

I just do not touch ksmbd version in linux kernel. ksmbd source in the latest linux kernel should be same with ksmbd 3.4.9.

@cyayon
Copy link

cyayon commented Mar 18, 2024

I have no idea how you could do...
I had the issue with macOS/iOS clients others than builtin/native operating system smb client. On these operating systems, I tried different applications like infuse and filebrowser (stratospherix).
I was thinking that Kodi also had the issue (related to this post).

@jcadduono
Copy link

@namjaejeon do you have a specific command you'd like the output from with tcpdump, ex. would this work?
tcpdump -i any -c100 -w smb.pcap port 445
I suppose I can upload a non-working pcap file (from linux mainline) and a working pcap file (from namjaejeon/ksmbd:master) to compare if that helps.

@namjaejeon
Copy link
Owner

namjaejeon commented Apr 1, 2024

@jcadduono

do you have a specific command you'd like the output from with tcpdump, ex. would this work?

I think that this command is okay.

I suppose I can upload a non-working pcap file (from linux mainline) and a working pcap file (from namjaejeon/ksmbd:master) to compare if that helps.

Yes, It would be very helpful if you give two dumpfiles to me!

@jcadduono
Copy link

jcadduono commented Apr 1, 2024

ksmbd-pcap-android.zip
(there are 3 attempts in the not-working pcap)

@namjaejeon
Copy link
Owner

@jcadduono Thanks for your help, I will check it:)

@namjaejeon
Copy link
Owner

@jcadduono Could you please check if problem is improved when applying the following change to your kernel ?

From 8b97f3f2bf397466f5f1e21419c716f2685be175 Mon Sep 17 00:00:00 2001
From: Namjae Jeon <linkinjeon@kernel.org>
Date: Tue, 2 Apr 2024 09:31:22 +0900
Subject: [PATCH] ksmbd: do not set SMB2_GLOBAL_CAP_ENCRYPTION for SMB 3.1.1

SMB2_GLOBAL_CAP_ENCRYPTION flag should be used only for 3.0 and 3.0.2 dialects.
This flags set cause compatibility problems with other SMB clients.

Signed-off-by: Namjae Jeon <linkinjeon@kernel.org>
---
 fs/smb/server/smb2ops.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/fs/smb/server/smb2ops.c b/fs/smb/server/smb2ops.c
index a45f7dca482e..606aa3c5189a 100644
--- a/fs/smb/server/smb2ops.c
+++ b/fs/smb/server/smb2ops.c
@@ -228,6 +228,11 @@ void init_smb3_0_server(struct ksmbd_conn *conn)
 	    conn->cli_cap & SMB2_GLOBAL_CAP_ENCRYPTION)
 		conn->vals->capabilities |= SMB2_GLOBAL_CAP_ENCRYPTION;
 
+	if (server_conf.flags & KSMBD_GLOBAL_FLAG_SMB2_ENCRYPTION ||
+	    (!(server_conf.flags & KSMBD_GLOBAL_FLAG_SMB2_ENCRYPTION_OFF) &&
+	     conn->cli_cap & SMB2_GLOBAL_CAP_ENCRYPTION))
+		conn->vals->capabilities |= SMB2_GLOBAL_CAP_ENCRYPTION;
+
 	if (server_conf.flags & KSMBD_GLOBAL_FLAG_SMB3_MULTICHANNEL)
 		conn->vals->capabilities |= SMB2_GLOBAL_CAP_MULTI_CHANNEL;
 }
@@ -278,11 +283,6 @@ int init_smb3_11_server(struct ksmbd_conn *conn)
 		conn->vals->capabilities |= SMB2_GLOBAL_CAP_LEASING |
 			SMB2_GLOBAL_CAP_DIRECTORY_LEASING;
 
-	if (server_conf.flags & KSMBD_GLOBAL_FLAG_SMB2_ENCRYPTION ||
-	    (!(server_conf.flags & KSMBD_GLOBAL_FLAG_SMB2_ENCRYPTION_OFF) &&
-	     conn->cli_cap & SMB2_GLOBAL_CAP_ENCRYPTION))
-		conn->vals->capabilities |= SMB2_GLOBAL_CAP_ENCRYPTION;
-
 	if (server_conf.flags & KSMBD_GLOBAL_FLAG_SMB3_MULTICHANNEL)
 		conn->vals->capabilities |= SMB2_GLOBAL_CAP_MULTI_CHANNEL;
 
-- 
2.34.1

@jcadduono
Copy link

@namjaejeon I can confirm it is working with my Android devices after applying this patch on Linux 6.8.1 ksmbd driver

@namjaejeon
Copy link
Owner

namjaejeon commented Apr 2, 2024

@jcadduono Really thanks! If you give me your real name and mail address, I will add it to the patch.

e.g.

Reported-by: Chao Ma <machao2019@gmail.com>
Signed-off-by: Namjae Jeon <linkinjeon@kernel.org>

Thanks for your help!

@jcadduono
Copy link

jcadduono commented Apr 2, 2024

Cool! It is James Christopher Adduono <jc@adduono.com>
Really appreciate how quickly you managed to diagnose & resolve this!

@namjaejeon
Copy link
Owner

namjaejeon commented Apr 2, 2024

@jcadduono Thanks for your report!
Applied it to my repo. It would be applied into mainline soon.
smfrench/smb3-kernel@2513c02

@flood404
Copy link
Author

flood404 commented Apr 3, 2024

Sorry I wasn't much helpful with capturing on the cause. That was way out of my scope on how to do it. I am glad that I did find an real issue and it seems it was confirmed by 2 people and someone patched it. The guy who does the DD-WRT that uses this ksmbd has fixed many things and it was somewhat related on how he coded it. I wasn't very sure I was contacting the right person.

@cyayon
Copy link

cyayon commented Apr 12, 2024

Hello,

I just upgraded to kernel 6.8.5 (archlinux distribution, which is supposed to include your patch) and test with included ksmbd module with a problematic client (Filebrowser app on macOS and iOS).

The issue is always here.

I used tcpdump to get a packets capture in attachment.
smb.pcap.zip

Here is the 6.8.5 smb2ops.c link https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/tree/fs/smb/server/smb2ops.c?h=v6.8.5

thanks.

@namjaejeon
Copy link
Owner

namjaejeon commented Apr 15, 2024

@cyayon Can you tell me what MacOS version is ? and can you give me wireshark dump with ksmbd 3.4.9 ? want to compare what command cause this problem ?

@cyayon
Copy link

cyayon commented Apr 15, 2024

Hi,
Filebrowser is an application (from AppStore) for iOS (iPhone/iPadOS) and MacOS (last versions for all OS and app).
Here is a tcpdump capture with a working ksmbd 3.4.9 (dkms).

smb_ok.pcap.zip

@namjaejeon
Copy link
Owner

@cyayon Hm.. I didn't find any clue when comparing packets.. Can you test https://github.com/namjaejeon/ksmbd master branch instead of 3.4.9. because there are more patches between 3.4.9 and the latest master.

@cyayon
Copy link

cyayon commented Apr 16, 2024

Hi,

The ksmbd included in vanilla kernel 6.8.5 do not work (like previous releases since < 6.6.10).
The ksmbd 3.4.9 loaded via dkms with the same kernel version work perfectly.

Do you want I test latest master branch (> 3.4.9) to confirm that it do not work anymore ?
The current ksmbd git/master is 3.2.1.r3718.39829e1, could you please confirm ?

Thanks

@namjaejeon
Copy link
Owner

namjaejeon commented Apr 16, 2024

@cyayon

Do you want I test latest master branch (> 3.4.9) to confirm that it do not work anymore ?

Yes. There are patches between the latest master and 3.4.9. want to know whether these patches affect this issue.

The current ksmbd git/master is 3.2.1.r3718.39829e1, could you please confirm ?

I have updated master branch. the top of patch on maser is "ksmbd: validate request buffer size in smb2_allocate_rsp_buf()"

Thanks for your help!

@cyayon
Copy link

cyayon commented Apr 16, 2024

Hi,

it seems to work properly with this version too :

filename:       /lib/modules/6.8.5-arch1-1/updates/dkms/ksmbd.ko.zst
softdep:        pre: crc32
softdep:        pre: gcm
softdep:        pre: ccm
softdep:        pre: aead2
softdep:        pre: sha512
softdep:        pre: sha256
softdep:        pre: cmac
softdep:        pre: aes
softdep:        pre: nls
softdep:        pre: md5
softdep:        pre: md4
softdep:        pre: hmac
softdep:        pre: ecb
license:        GPL
description:    Linux kernel CIFS/SMB SERVER
version:        3.4.9
author:         Namjae Jeon <linkinjeon@kernel.org>
srcversion:     2718ACAA96C085069E08A11
depends:        ib_core,rdma_cm,libdes
retpoline:      Y
name:           ksmbd
vermagic:       6.8.5-arch1-1 SMP preempt mod_unload
sig_id:         PKCS#7
signer:         DKMS module signing key
sig_key:        5F:DB:57:13:7E:6A:C4:FA:53:84:31:7A:8C:97:DB:25:75:9E:D0:06
sig_hashalgo:   sha512
signature:      07:87:78:1A:30:E0:D7:8C:A4:95:E6:D7:85:0D:5B:B5:AD:94:A1:5B:
                71:5D:11:25:9C:2B:8B:E8:3B:6D:44:EC:8D:F2:BF:8D:6A:9B:35:B3:
                14:F3:D7:A8:56:AB:79:A2:C0:0A:A5:30:22:3B:99:08:88:52:AF:21:
                72:0E:58:B8:EB:58:E1:5E:90:2F:31:4C:D3:C7:F0:5E:76:2C:BF:2D:
                C8:93:9C:2A:62:AA:AA:8C:BD:D4:E9:51:86:40:97:D3:F9:3B:BD:81:
                C3:47:F5:E7:05:F3:72:43:C6:B8:11:C3:68:45:0A:DE:5E:B8:97:CE:
                6C:8C:8C:B3:06:72:99:22:8C:BB:71:D1:40:AD:39:0C:40:BA:B5:D7:
                24:98:87:37:67:32:21:FA:D8:96:8E:24:A4:41:94:D8:DD:5A:3E:50:
                E4:99:5C:9F:6F:19:B7:18:74:52:4F:24:E9:EF:F4:E1:E5:C5:BD:F1:
                B5:15:58:47:A3:2D:55:48:32:5E:29:D4:A4:83:E2:11:55:61:64:E1:
                6F:3B:CB:FA:6B:F8:65:5F:FB:7C:81:8B:C4:37:0B:4F:DF:08:32:58:
                2C:0F:72:0F:B2:D5:ED:20:41:36:68:4D:BF:4F:FE:AA:30:B6:E7:03:
                E6:AD:AD:94:BF:0F:20:6D:85:36:16:94:B4:EF:8E:AB

@namjaejeon
Copy link
Owner

it seems to work properly with this version too :

I don't know what dkms version of ksmbd is. I understood that it use ksmbd 3.4.9 release (https://github.com/cifsd-team/ksmbd/releases/tag/3.4.9)

@cyayon
Copy link

cyayon commented Apr 16, 2024

no, it is the very last version, including your last patch : ksmbd-git-dkms-3.2.1.r3721.5f00283-1

@namjaejeon
Copy link
Owner

@cyayon Okay... Let me check dump files you gave me.

@namjaejeon
Copy link
Owner

@cyayon Can you dump one more on 3.4.9 dkms version ?

@cyayon
Copy link

cyayon commented Apr 16, 2024

your last git master branch or release version 3.4.9 please?

@namjaejeon
Copy link
Owner

@cyayon It doesn't matter which of the two.

@cyayon
Copy link

cyayon commented Apr 16, 2024

Here is a tcpdump for the last master git version.
smb_master.pcap.zip

@namjaejeon
Copy link
Owner

@cyayon Thanks!

@namjaejeon
Copy link
Owner

namjaejeon commented Apr 17, 2024

@cyayon Really sorry, Can you dump one more on problem situation ? there is no clue on both dumps. So I want to re-check new dumps.

@cyayon
Copy link

cyayon commented Apr 17, 2024

Hi,

no problem, here is a capture with stock ksmbd module included in kernel 6.8.5.
smb_ko.pcap.zip

@namjaejeon
Copy link
Owner

@cyayon Thanks for your help!

Can you test this patch after applying it to your 6.8.5 kernel ?

diff --git a/fs/smb/common/smb2pdu.h b/fs/smb/common/smb2pdu.h
index 1b594307c9d5..202ff9128156 100644
--- a/fs/smb/common/smb2pdu.h
+++ b/fs/smb/common/smb2pdu.h
@@ -711,7 +711,7 @@ struct smb2_close_rsp {
        __le16 StructureSize; /* 60 */
        __le16 Flags;
        __le32 Reserved;
-       struct_group(network_open_info,
+       struct_group_attr(network_open_info, __packed,
                __le64 CreationTime;
                __le64 LastAccessTime;
                __le64 LastWriteTime;

@cyayon
Copy link

cyayon commented Apr 19, 2024

Hello,

It seems to work as expected.
great !
thanks.

@namjaejeon
Copy link
Owner

@cyayon Thanks for your check and help! I will apply it to the mainline. And let me know if you have any issue. Thanks again!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants