@@ -146,12 +146,12 @@ enum Trace {
146146 message : SpToHost ,
147147 } ,
148148 ApobWriteError {
149- offset : u64 ,
149+ offset : u32 ,
150150 #[ count( children) ]
151151 err : drv_hf_api:: ApobWriteError ,
152152 } ,
153153 ApobReadError {
154- offset : u64 ,
154+ offset : u32 ,
155155 #[ count( children) ]
156156 err : drv_hf_api:: ApobReadError ,
157157 } ,
@@ -1035,32 +1035,9 @@ impl ServerImpl {
10351035 }
10361036 }
10371037 HostToSp :: ApobBegin { length, algorithm } => {
1038- // Decode into internal types, then call into `hf`
1039- // XXX should bad hash algorithms or lengths lock the APOB?
1040- use drv_hf_api:: { ApobBeginError , ApobHash } ;
1041- use host_sp_messages:: ApobBeginResult ;
1042- Some ( SpToHost :: ApobBegin ( match algorithm {
1043- 0 => {
1044- if let Ok ( d) = data. try_into ( ) {
1045- let hash = ApobHash :: Sha256 ( d) ;
1046- match self . hf . apob_begin ( length, hash) {
1047- Ok ( ( ) ) => ApobBeginResult :: Ok ,
1048- Err ( ApobBeginError :: NotImplemented ) => {
1049- ApobBeginResult :: NotImplemented
1050- }
1051- Err ( ApobBeginError :: InvalidState ) => {
1052- ApobBeginResult :: InvalidState
1053- }
1054- Err ( ApobBeginError :: BadDataLength ) => {
1055- ApobBeginResult :: BadDataLength
1056- }
1057- }
1058- } else {
1059- ApobBeginResult :: BadHashLength
1060- }
1061- }
1062- _ => ApobBeginResult :: InvalidAlgorithm ,
1063- } ) )
1038+ Some ( SpToHost :: ApobBegin ( Self :: apob_begin (
1039+ & self . hf , length, algorithm, data,
1040+ ) ) )
10641041 }
10651042 HostToSp :: ApobCommit => {
10661043 // Call into `hf` to do the work here
@@ -1118,6 +1095,43 @@ impl ServerImpl {
11181095 Ok ( ( ) )
11191096 }
11201097
1098+ fn apob_begin (
1099+ hf : & HostFlash ,
1100+ length : u64 ,
1101+ algorithm : u8 ,
1102+ data : & [ u8 ] ,
1103+ ) -> host_sp_messages:: ApobBeginResult {
1104+ // Decode into internal types, then call into `hf`
1105+ // XXX should bad hash algorithms or lengths lock the APOB?
1106+ use drv_hf_api:: { ApobBeginError , ApobHash } ;
1107+ use host_sp_messages:: ApobBeginResult ;
1108+ let Ok ( length) = u32:: try_from ( length) else {
1109+ return host_sp_messages:: ApobBeginResult :: BadDataLength ;
1110+ } ;
1111+ match algorithm {
1112+ 0 => {
1113+ if let Ok ( d) = data. try_into ( ) {
1114+ let hash = ApobHash :: Sha256 ( d) ;
1115+ match hf. apob_begin ( length, hash) {
1116+ Ok ( ( ) ) => ApobBeginResult :: Ok ,
1117+ Err ( ApobBeginError :: NotImplemented ) => {
1118+ ApobBeginResult :: NotImplemented
1119+ }
1120+ Err ( ApobBeginError :: InvalidState ) => {
1121+ ApobBeginResult :: InvalidState
1122+ }
1123+ Err ( ApobBeginError :: BadDataLength ) => {
1124+ ApobBeginResult :: BadDataLength
1125+ }
1126+ }
1127+ } else {
1128+ ApobBeginResult :: BadHashLength
1129+ }
1130+ }
1131+ _ => ApobBeginResult :: InvalidAlgorithm ,
1132+ }
1133+ }
1134+
11211135 /// Write data to the bonus region of flash
11221136 ///
11231137 /// This does not take `&self` because we need to force a split borrow
@@ -1128,6 +1142,9 @@ impl ServerImpl {
11281142 ) -> host_sp_messages:: ApobDataResult {
11291143 use drv_hf_api:: ApobWriteError ;
11301144 use host_sp_messages:: ApobDataResult ;
1145+ let Ok ( offset) = u32:: try_from ( offset) else {
1146+ return ApobDataResult :: InvalidOffset ;
1147+ } ;
11311148 match hf. apob_write ( offset, data) {
11321149 Ok ( ( ) ) => ApobDataResult :: Ok ,
11331150 Err ( err) => {
@@ -1162,6 +1179,14 @@ impl ServerImpl {
11621179 ) ;
11631180 return ;
11641181 } ;
1182+ let Ok ( offset) = u32:: try_from ( offset) else {
1183+ self . tx_buf . encode_response (
1184+ sequence,
1185+ & SpToHost :: ApobRead ( ApobReadResult :: InvalidOffset ) ,
1186+ |_buf| 0 ,
1187+ ) ;
1188+ return ;
1189+ } ;
11651190 self . tx_buf . try_encode_response (
11661191 sequence,
11671192 & SpToHost :: ApobRead ( ApobReadResult :: Ok ) ,
0 commit comments