From: ChenXiaoSong chenxiaosong@kylinos.cn
[ Upstream commit dafe22bc676d4fcb1ccb193c8cc3dda57942509d ]
__process_request() will not print error messages if smb2_query_dir() always returns 0.
Fix this by returning the correct value at the end of function.
Signed-off-by: ChenXiaoSong chenxiaosong@kylinos.cn Acked-by: Namjae Jeon linkinjeon@kernel.org Signed-off-by: Steve French stfrench@microsoft.com Signed-off-by: Sasha Levin sashal@kernel.org ---
LLM Generated explanations, may be completely bogus:
## Analysis of smb/server: fix return value of smb2_query_dir()
### 1. COMMIT MESSAGE ANALYSIS
The commit message clearly states: - `__process_request()` will not print error messages if `smb2_query_dir()` always returns 0 - The fix returns the correct error value `rc` instead of 0
**Notable absences:** - No `Cc: stable@vger.kernel.org` tag - No `Fixes:` tag identifying when the bug was introduced
**Positive signals:** - Acked by Namjae Jeon (ksmbd maintainer) - Signed off by Steve French (SMB maintainer)
### 2. CODE CHANGE ANALYSIS
The change is a single-line fix in the error handling path:
```c - return 0; + return rc; ```
**Technical mechanism of the bug:** Looking at the context, this is in an error handling block where: 1. `rc` contains an error code (-EINVAL, -EACCES, -ENOENT, -EBADF, -ENOMEM, -EFAULT, or -EIO) 2. The appropriate SMB status is set in `rsp->hdr.Status` 3. Error response is prepared with `smb2_set_err_rsp(work)` 4. Cleanup is done with `ksmbd_fd_put()` and `ksmbd_revert_fsids()` 5. **BUG**: The function returns 0 (success) instead of `rc` (the actual error)
**Root cause:** The caller `__process_request()` uses the return value to determine if an error occurred. Returning 0 masks all errors, preventing proper error logging and handling.
### 3. CLASSIFICATION
This is a **bug fix** - incorrect error return value handling. The function was silently discarding error information that callers need.
### 4. SCOPE AND RISK ASSESSMENT
| Factor | Assessment | |--------|------------| | Lines changed | 1 | | Files touched | 1 | | Complexity | Trivial | | Subsystem | ksmbd (kernel SMB server) | | Risk level | **Very Low** |
The fix is surgical and obviously correct - the `rc` variable already contains the appropriate error code, it just wasn't being returned.
### 5. USER IMPACT
- **Affected users:** ksmbd server users - **Severity:** Medium - error conditions in directory queries are not properly reported - **Consequences of the bug:** - Error messages not printed when they should be - Callers may not handle error conditions properly - Debugging ksmbd issues becomes harder
### 6. STABILITY INDICATORS
- Acked by ksmbd maintainer - Signed off by SMB maintainer - Simple, self-contained change
### 7. DEPENDENCY CHECK
- No dependencies on other commits - ksmbd has been in the kernel since 5.15 - The fix applies to existing code paths
### STABLE KERNEL CRITERIA EVALUATION
| Criterion | Met? | Notes | |-----------|------|-------| | Obviously correct | ✅ | Trivially correct - return error code instead of 0 | | Fixes real bug | ✅ | Error propagation was broken | | Small and contained | ✅ | Single line change | | No new features | ✅ | Pure bug fix | | Tested | ⚠️ | No Tested-by tag, but very low risk |
### RISK VS BENEFIT
**Benefits:** - Fixes broken error propagation in ksmbd directory queries - Enables proper error logging for debugging - Very low risk due to trivial nature of fix
**Risks:** - Minimal - the change is from "always return 0" to "return actual error code" - Behavior change only affects error paths
### CONCLUSION
This is a straightforward, obviously correct bug fix. The function was incorrectly returning 0 (success) in all error cases, causing error information to be lost. The fix is a single line change that returns the actual error code that was already being computed.
While the commit lacks explicit stable tags, it meets all stable criteria: obviously correct, fixes a real bug affecting error handling, trivially small scope, and no new features. The risk is minimal and the fix improves error handling in ksmbd.
**YES**
fs/smb/server/smb2pdu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/fs/smb/server/smb2pdu.c b/fs/smb/server/smb2pdu.c index f901ae18e68ad..8975b6f2f5800 100644 --- a/fs/smb/server/smb2pdu.c +++ b/fs/smb/server/smb2pdu.c @@ -4560,7 +4560,7 @@ int smb2_query_dir(struct ksmbd_work *work) smb2_set_err_rsp(work); ksmbd_fd_put(work, dir_fp); ksmbd_revert_fsids(work); - return 0; + return rc; }
/**