|
| 1 | +From ea3f38358efcfe9703eca3e8d024a12080d742ee Mon Sep 17 00:00:00 2001 |
| 2 | +From: Jakub Witczak < [email protected]> |
| 3 | +Date: Wed, 27 Aug 2025 17:49:08 +0200 |
| 4 | +Subject: [PATCH 1/2] ssh: verify file handle size limit for client data |
| 5 | + |
| 6 | +- reject handles exceeding 256 bytes (as specified for SFTP) |
| 7 | +--- |
| 8 | + lib/ssh/src/ssh_sftpd.erl | 11 +++++++++++ |
| 9 | + 1 file changed, 11 insertions(+) |
| 10 | + |
| 11 | +diff --git a/lib/ssh/src/ssh_sftpd.erl b/lib/ssh/src/ssh_sftpd.erl |
| 12 | +index f3d8053..5120884 100644 |
| 13 | +--- a/lib/ssh/src/ssh_sftpd.erl |
| 14 | ++++ b/lib/ssh/src/ssh_sftpd.erl |
| 15 | +@@ -222,6 +222,17 @@ handle_data(Type, ChannelId, Data0, State = #state{pending = Pending}) -> |
| 16 | + handle_data(Type, ChannelId, Data, State#state{pending = <<>>}) |
| 17 | + end. |
| 18 | + |
| 19 | ++%% From draft-ietf-secsh-filexfer-02 "The file handle strings MUST NOT be longer than 256 bytes." |
| 20 | ++handle_op(Request, ReqId, <<?UINT32(HLen), _/binary>>, State = #state{xf = XF}) |
| 21 | ++ when (Request == ?SSH_FXP_CLOSE orelse |
| 22 | ++ Request == ?SSH_FXP_FSETSTAT orelse |
| 23 | ++ Request == ?SSH_FXP_FSTAT orelse |
| 24 | ++ Request == ?SSH_FXP_READ orelse |
| 25 | ++ Request == ?SSH_FXP_READDIR orelse |
| 26 | ++ Request == ?SSH_FXP_WRITE), |
| 27 | ++ HLen > 256 -> |
| 28 | ++ ssh_xfer:xf_send_status(XF, ReqId, ?SSH_FX_INVALID_HANDLE, "Invalid handle"), |
| 29 | ++ State; |
| 30 | + handle_op(?SSH_FXP_INIT, Version, B, State) when is_binary(B) -> |
| 31 | + XF = State#state.xf, |
| 32 | + Vsn = lists:min([XF#ssh_xfer.vsn, Version]), |
| 33 | +-- |
| 34 | +2.45.4 |
| 35 | + |
| 36 | + |
| 37 | +From 5aca35b5d186e7211496f92a7d1a909634960c04 Mon Sep 17 00:00:00 2001 |
| 38 | +From: Jakub Witczak < [email protected]> |
| 39 | +Date: Wed, 27 Aug 2025 17:49:53 +0200 |
| 40 | +Subject: [PATCH 2/2] ssh: code formatting |
| 41 | + |
| 42 | +Signed-off-by: Azure Linux Security Servicing Account < [email protected]> |
| 43 | +Upstream-reference: https://patch-diff.githubusercontent.com/raw/erlang/otp/pull/10156.patch |
| 44 | +--- |
| 45 | + lib/ssh/src/ssh_sftpd.erl | 8 +++----- |
| 46 | + 1 file changed, 3 insertions(+), 5 deletions(-) |
| 47 | + |
| 48 | +diff --git a/lib/ssh/src/ssh_sftpd.erl b/lib/ssh/src/ssh_sftpd.erl |
| 49 | +index 5120884..fec6527 100644 |
| 50 | +--- a/lib/ssh/src/ssh_sftpd.erl |
| 51 | ++++ b/lib/ssh/src/ssh_sftpd.erl |
| 52 | +@@ -240,7 +240,7 @@ handle_op(?SSH_FXP_INIT, Version, B, State) when is_binary(B) -> |
| 53 | + ssh_xfer:xf_send_reply(XF1, ?SSH_FXP_VERSION, <<?UINT32(Vsn)>>), |
| 54 | + State#state{xf = XF1}; |
| 55 | + handle_op(?SSH_FXP_REALPATH, ReqId, |
| 56 | +- <<?UINT32(Rlen), RPath:Rlen/binary>>, |
| 57 | ++ <<?UINT32(RLen), RPath:RLen/binary>>, |
| 58 | + State0) -> |
| 59 | + RelPath = relate_file_name(RPath, State0, _Canonicalize=false), |
| 60 | + {Res, State} = resolve_symlinks(RelPath, State0), |
| 61 | +@@ -409,14 +409,12 @@ handle_op(?SSH_FXP_RMDIR, ReqId, <<?UINT32(PLen), BPath:PLen/binary>>, |
| 62 | + send_status(Status, ReqId, State1); |
| 63 | + |
| 64 | + handle_op(?SSH_FXP_RENAME, ReqId, |
| 65 | +- Bin = <<?UINT32(PLen), _:PLen/binary, ?UINT32(PLen2), |
| 66 | +- _:PLen2/binary>>, |
| 67 | ++ Bin = <<?UINT32(PLen), _:PLen/binary, ?UINT32(PLen2), _:PLen2/binary>>, |
| 68 | + State = #state{xf = #ssh_xfer{vsn = Vsn}}) when Vsn==3; Vsn==4 -> |
| 69 | + handle_op(?SSH_FXP_RENAME, ReqId, <<Bin/binary, 0:32>>, State); |
| 70 | + |
| 71 | + handle_op(?SSH_FXP_RENAME, ReqId, |
| 72 | +- <<?UINT32(PLen), BPath:PLen/binary, ?UINT32(PLen2), |
| 73 | +- BPath2:PLen2/binary, ?UINT32(Flags)>>, |
| 74 | ++ <<?UINT32(PLen), BPath:PLen/binary, ?UINT32(PLen2), BPath2:PLen2/binary, ?UINT32(Flags)>>, |
| 75 | + State0 = #state{file_handler = FileMod, file_state = FS0}) -> |
| 76 | + Path = relate_file_name(BPath, State0), |
| 77 | + Path2 = relate_file_name(BPath2, State0), |
| 78 | +-- |
| 79 | +2.45.4 |
| 80 | + |
0 commit comments