@@ -68,15 +68,13 @@ static void _mpir_cleanup(void);
6868static void _mpir_dump_proctable (void );
6969static void _pty_restore (void );
7070static void print_layout_info (slurm_step_layout_t * layout );
71- static slurm_cred_t * _generate_fake_cred (slurm_step_id_t stepid ,
72- uid_t uid , char * nodelist ,
73- uint32_t node_cnt );
71+ static char * _generate_io_key (void );
7472static uint32_t _nodeid_from_layout (slurm_step_layout_t * layout ,
7573 uint32_t taskid );
7674static void _set_exit_code (void );
7775static int _attach_to_tasks (slurm_step_id_t stepid ,
7876 slurm_step_layout_t * layout ,
79- slurm_cred_t * fake_cred ,
77+ char * io_key ,
8078 uint16_t num_resp_ports ,
8179 uint16_t * resp_ports ,
8280 int num_io_ports ,
@@ -118,11 +116,10 @@ int sattach(int argc, char **argv)
118116{
119117 log_options_t logopt = LOG_OPTS_STDERR_ONLY ;
120118 slurm_step_layout_t * layout ;
121- slurm_cred_t * fake_cred ;
122119 message_thread_state_t * mts ;
123120 uint32_t jobid , stepid ;
124121 client_io_t * io ;
125- char * hosts ;
122+ char * io_key = NULL ;
126123
127124 slurm_init (NULL );
128125 log_init (xbasename (argv [0 ]), logopt , 0 , NULL );
@@ -169,16 +166,11 @@ int sattach(int argc, char **argv)
169166 _nodeid_from_layout (layout , opt .fds .input .taskid );
170167 }
171168
172- if (layout -> front_end )
173- hosts = layout -> front_end ;
174- else
175- hosts = layout -> node_list ;
176- fake_cred = _generate_fake_cred (opt .selected_step -> step_id ,
177- opt .uid , hosts , layout -> node_cnt );
169+ io_key = _generate_io_key ();
178170 mts = _msg_thr_create (layout -> node_cnt , layout -> task_cnt );
179171
180172 io = client_io_handler_create (opt .fds , layout -> task_cnt ,
181- layout -> node_cnt , fake_cred ,
173+ layout -> node_cnt , io_key ,
182174 opt .labelio , NO_VAL , NO_VAL );
183175 client_io_handler_start (io );
184176
@@ -197,7 +189,7 @@ int sattach(int argc, char **argv)
197189 xsignal_block (pty_sigarray );
198190 }
199191
200- _attach_to_tasks (opt .selected_step -> step_id , layout , fake_cred ,
192+ _attach_to_tasks (opt .selected_step -> step_id , layout , io_key ,
201193 mts -> num_resp_port , mts -> resp_port ,
202194 io -> num_listen , io -> listenport ,
203195 mts -> tasks_started );
@@ -213,6 +205,7 @@ int sattach(int argc, char **argv)
213205 client_io_handler_finish (io );
214206 client_io_handler_destroy (io );
215207 _mpir_cleanup ();
208+ xfree (io_key );
216209
217210 return global_rc ;
218211}
@@ -278,44 +271,22 @@ static void print_layout_info(slurm_step_layout_t *layout)
278271 hostlist_destroy (nl );
279272}
280273
281-
282- /* return a faked job credential */
283- static slurm_cred_t * _generate_fake_cred (slurm_step_id_t stepid ,
284- uid_t uid , char * nodelist ,
285- uint32_t node_cnt )
274+ /*
275+ * The io_key requires a modest amount of entropy to prevent someone guessing
276+ * it, then racing to initiate a connection to the sattach command.
277+ * By (ab)using the auth token generation mechanisms, the key should be
278+ * sufficiently random for our purposes. (An attacker would need to request
279+ * an auth key be generated at the same time by the same uid on the same host.)
280+ */
281+ static char * _generate_io_key (void )
286282{
287- slurm_cred_t * cred ;
288- slurm_cred_arg_t * arg = xmalloc (sizeof (* arg ));
289-
290- arg -> step_id .job_id = stepid .job_id ;
291- arg -> step_id .step_id = stepid .step_id ;
292- arg -> step_id .step_het_comp = stepid .step_het_comp ;
293- arg -> uid = uid ;
294-
295- arg -> job_hostlist = nodelist ;
296- arg -> job_nhosts = node_cnt ;
297-
298- arg -> step_hostlist = nodelist ;
299-
300- arg -> job_core_bitmap = bit_alloc (node_cnt );
301- bit_set_all (arg -> job_core_bitmap );
302- arg -> step_core_bitmap = bit_alloc (node_cnt );
303- bit_set_all (arg -> step_core_bitmap );
304-
305- arg -> cores_per_socket = xmalloc (sizeof (uint16_t ));
306- arg -> cores_per_socket [0 ] = 1 ;
307- arg -> sockets_per_node = xmalloc (sizeof (uint16_t ));
308- arg -> sockets_per_node [0 ] = 1 ;
309- arg -> sock_core_rep_count = xmalloc (sizeof (uint32_t ));
310- arg -> sock_core_rep_count [0 ] = node_cnt ;
311-
312- cred = slurm_cred_faker (arg );
313-
314- /* Don't free, this memory will be free'd later */
315- arg -> job_hostlist = NULL ;
316- arg -> step_hostlist = NULL ;
317- slurm_cred_free_args (arg );
318- return cred ;
283+ char * key = auth_g_create (AUTH_DEFAULT_INDEX , slurm_conf .authinfo ,
284+ 0 , NULL , 0 );
285+
286+ if (!key )
287+ fatal ("failed to generate a suitable io_key" );
288+
289+ return key ;
319290}
320291
321292void _handle_response_msg (slurm_msg_type_t msg_type , void * msg ,
@@ -383,7 +354,7 @@ void _handle_response_msg_list(List other_nodes_resp, bitstr_t *tasks_started)
383354 */
384355static int _attach_to_tasks (slurm_step_id_t stepid ,
385356 slurm_step_layout_t * layout ,
386- slurm_cred_t * fake_cred ,
357+ char * io_key ,
387358 uint16_t num_resp_ports ,
388359 uint16_t * resp_ports ,
389360 int num_io_ports ,
@@ -402,7 +373,7 @@ static int _attach_to_tasks(slurm_step_id_t stepid,
402373 reattach_msg .num_resp_port = num_resp_ports ;
403374 reattach_msg .resp_port = resp_ports ; /* array of response ports */
404375 reattach_msg .num_io_port = num_io_ports ;
405- reattach_msg .io_key = slurm_cred_get_signature ( fake_cred );
376+ reattach_msg .io_key = xstrdup ( io_key );
406377 reattach_msg .io_port = io_ports ;
407378
408379 slurm_msg_set_r_uid (& msg , SLURM_AUTH_UID_ANY );
0 commit comments