namjaejeon / ksmbd

ksmbd kernel server(SMB/CIFS server)
https://github.com/cifsd-team/ksmbd
282 stars 64 forks source link

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

Closed flood404 closed 1 week ago

flood404 commented 9 months ago

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 commented 9 months ago

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

flood404 commented 9 months ago

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 commented 9 months ago

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 commented 9 months ago

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 commented 9 months ago

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 commented 8 months ago

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

namjaejeon commented 8 months ago

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 commented 8 months ago

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 commented 8 months ago

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

namjaejeon commented 8 months ago

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 commented 8 months ago

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

namjaejeon commented 8 months ago

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

cyayon commented 8 months ago

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 commented 8 months ago

@cyayon Thanks for your comment.

flood404 commented 8 months ago

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 commented 8 months ago

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

namjaejeon commented 8 months ago

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

cyayon commented 8 months ago

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

namjaejeon commented 8 months ago

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 commented 8 months ago

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 commented 8 months ago

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 commented 8 months ago

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 commented 8 months ago

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

cyayon commented 8 months ago

https://github.com/namjaejeon/ksmbd/issues/476#issuecomment-1994035555

namjaejeon commented 8 months ago

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 commented 8 months ago

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 commented 8 months ago

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

namjaejeon commented 8 months ago

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

namjaejeon commented 8 months ago

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 commented 8 months ago

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).

namjaejeon commented 8 months ago

Okay, I need your help to fix it. Could you please give me wireshark (or tcpdump) file on problem situation ? And give me another wireshark dump when using dkms ksmbd 3.4.9. I want to compare the packets and find the clue.

cyayon commented 8 months ago

ok, I will try to do this before the end of the week.

namjaejeon commented 8 months ago

Really thanks! When dumping two dumps, Please use the same application scenario to easily compare them.

cyayon commented 8 months ago

could I use tcpdump on the server (ksmbd) side ? I can use Wireshark but only on the client side (macOS).

namjaejeon commented 8 months ago

could I use tcpdump on the server (ksmbd) side ?

No problem.

jcadduono commented 7 months ago

thanks, I was unable to access shares from the nvidia shield tv "mount NAS" feature with smb shares hosted from my NAS running Linux 6.8.1. after swapping ksmbd from vanilla Linux 6.8.1 (ksmbd 3.4.2) to namjaejeon/ksmbd:master and rebuilding the kernel, it mounts fine!

namjaejeon commented 7 months ago

@jcadduono Can you dump wireshark(or tcpdump) on problem situation ?

jcadduono commented 7 months ago

@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 commented 7 months ago

@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 commented 7 months ago

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

namjaejeon commented 7 months ago

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

namjaejeon commented 7 months ago

@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 commented 7 months ago

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

namjaejeon commented 7 months ago

@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 commented 7 months ago

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

namjaejeon commented 7 months ago

@jcadduono Thanks for your report! Applied it to my repo. It would be applied into mainline soon. https://github.com/smfrench/smb3-kernel/commit/2513c027bd42b322b2e8eff2ebd7ad7a72f2cdbe

flood404 commented 7 months ago

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 commented 7 months ago

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 commented 7 months ago

@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 commented 7 months ago

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