@@ -53,27 +53,28 @@ def find_ioctl_first_case_uses(ioctl_handler, kernel_folder):
5353 for idx , line in enumerate (content .split ('\n ' )):
5454 already_seen = set ()
5555 for ioctl in ioctl_handler ['ioctls' ]:
56- if ioctl .name in line and ioctl .name not in already_seen and 'case' in line :
56+ if (ioctl .name in line and ioctl .name not in already_seen
57+ and 'case' in line ):
5758 logger .debug ("%s :: %d" , line .replace ("\n " , "" ), idx )
5859 already_seen .add (ioctl .name )
5960 pair_starts .append ((ioctl .name , idx + 1 ))
6061 return pair_starts
6162
6263
63- def extract_header_files_referenced (workdir , all_sources ) -> Set [str ]:
64+ def extract_header_files_referenced (workdir ) -> Set [str ]:
6465 """extract the source of all header files from FI output."""
6566
6667 raw_header_file_references = fuzz_introspector_utils .get_all_header_files_in_light (
67- workdir , all_sources )
68+ workdir )
6869
6970 all_files = set ()
7071 for raw_file_reference in raw_header_file_references :
71- logger .info ('Header file -: %s' , raw_file_reference )
72+ logger .debug ('Header file -: %s' , raw_file_reference )
7273 path2 = raw_file_reference .replace ('file_location:' ,
7374 '' ).strip ().split (':' )[0 ].replace (
7475 "'" , '' )
7576 normalized = os .path .normpath (path2 )
76- logger .info ('Adding %s' , normalized )
77+ logger .debug ('Adding %s' , normalized )
7778 all_files .add (normalized )
7879
7980 logger .debug ('Files found' )
@@ -99,13 +100,13 @@ def extract_header_files_referenced(workdir, all_sources) -> Set[str]:
99100 '>' , '' ).replace ('<' , '' ).replace ('\" ' ,
100101 '' ).replace (' ' , '' )
101102
102- logger .info ('Including: %s' , header_included )
103+ logger .debug ('Including: %s' , header_included )
103104 new_files .add (header_included )
104105 all_files = all_files .union (new_files )
105106
106107 found_files = []
107108 for header_file in all_files :
108- logger .info ('Finding F1' )
109+ logger .debug ('Finding F1' )
109110 valid_target = textual_source_analysis .find_file (header_file )
110111 if valid_target :
111112 found_files .append (valid_target )
@@ -115,8 +116,7 @@ def extract_header_files_referenced(workdir, all_sources) -> Set[str]:
115116 return found_files
116117
117118
118- def extract_syzkaller_types_to_analyze (ioctls , syzkaller_description ,
119- typedict ) -> Dict [str , str ]:
119+ def extract_syzkaller_types_to_analyze (ioctls , typedict ) -> Dict [str , str ]:
120120 """goes through ioctls_per_fp and syzkaller_description, and sets something
121121 in syzkaller_description and returns a set of types to analyse."""
122122
@@ -181,8 +181,8 @@ def extract_syzkaller_types_to_analyze(ioctls, syzkaller_description,
181181 target = '%s array[%s, %s]' % (field_name , arr_type ,
182182 array_count )
183183 else :
184- target = '%s %s' % ( syz_name , syz_type )
185- description_str += ' %s \n ' % ( target )
184+ target = f' { syz_name } { syz_type } '
185+ description_str += f' { target } \n '
186186
187187 description_str += '}'
188188 description_types [dtype ] = description_str
@@ -201,7 +201,7 @@ def get_next_syzkaller_workdir():
201201
202202
203203def write_syzkaller_description (ioctls , syzkaller_description , workdir ,
204- all_devnodes , header_file , target_path ):
204+ all_devnodes , target_path ):
205205 """Writes a description-X.txt representing syzkaller description."""
206206
207207 # Ensure there are actually ioctls to generate
@@ -257,7 +257,7 @@ def write_syzkaller_description(ioctls, syzkaller_description, workdir,
257257 f .write ('\n ' * 2 )
258258
259259 # Describe the types
260- for st , text in syzkaller_description .items (): #['types']:
260+ for _ , text in syzkaller_description .items (): #['types']:
261261 f .write (text )
262262 f .write ('\n ' * 2 )
263263 return next_syz_descr
@@ -274,13 +274,12 @@ def get_function_containing_line_idx(line_idx, sorted_functions):
274274 return None
275275
276276
277- def check_source_files_for_ioctl (kernel_folder , src_file , ioctls ,
278- all_files_with_func ):
277+ def check_source_files_for_ioctl (src_file , ioctls , all_files_with_func ):
279278 """For a given set of of IOCTLs and a source file, finds the functions
280279 in the source file from the `all_files_with_func` that uses the IOCTLs."""
281280 all_ioctl_func_handlers = list ()
282281
283- logger .info ('Finding F2 ' )
282+ logger .info ('Finding source files with ioctls usage. ' )
284283 target_file = textual_source_analysis .find_file (src_file )
285284 if not target_file :
286285 return []
@@ -323,14 +322,10 @@ def check_source_files_for_ioctl(kernel_folder, src_file, ioctls,
323322
324323 if len (functions_with_ioctls_in_them ) > 0 :
325324 logger .debug ('Functions with ioctls in them' )
326- for interesting_func in functions_with_ioctls_in_them :
327- all_ioctl_func_handlers .append (
328- functions_with_ioctls_in_them [interesting_func ])
329- logger .debug (
330- "- %s" ,
331- functions_with_ioctls_in_them [interesting_func ]['func' ])
332- for ioctl in functions_with_ioctls_in_them [interesting_func ][
333- 'ioctls' ]:
325+ for func_obj in functions_with_ioctls_in_them .values ():
326+ all_ioctl_func_handlers .append (func_obj )
327+ logger .debug ("- %s" , func_obj ['func' ])
328+ for ioctl in func_obj ['ioctls' ]:
334329 logger .debug (' - %s' , (ioctl .name ))
335330
336331 return all_ioctl_func_handlers
@@ -375,7 +370,7 @@ def find_all_unlocked_ioctls(source_files_to_functions_mapping):
375370 return unlocked_ioctl_functions
376371
377372
378- def get_ioctl_handlers (ioctls , kernel_folder , report , fi_data_dir ):
373+ def get_ioctl_handlers (ioctls , kernel_folder , fi_data_dir ):
379374 """Finds the places in the source code where IOCTL commands are used."""
380375
381376 logger .info ('Getting ioctl handlers' )
@@ -408,8 +403,7 @@ def get_ioctl_handlers(ioctls, kernel_folder, report, fi_data_dir):
408403
409404 for src_file in source_files_to_functions_mapping :
410405 tmp_ioctl_handlers = check_source_files_for_ioctl (
411- kernel_folder , src_file , ioctls ,
412- source_files_to_functions_mapping )
406+ src_file , ioctls , source_files_to_functions_mapping )
413407 ioctl_handlers += tmp_ioctl_handlers
414408
415409 for unlocked_ioctl_handler in unlocked_ioctl_handlers :
@@ -667,9 +661,8 @@ def extract_types_of_syzkaller_description(ioctls, fi_data_dir):
667661 type_dict ['structs' ] += struct_list
668662 type_dict ['typedefs' ] += typedefs
669663
670- syzkaller_description = {'types' : dict ()}
671664 all_types_to_decipher = extract_syzkaller_types_to_analyze (
672- ioctls , syzkaller_description , type_dict )
665+ ioctls , type_dict )
673666
674667 logger .info ('All types extracted from struct to include in description:' )
675668 logger .info (json .dumps (list (all_types_to_decipher ), indent = 2 ))
@@ -695,11 +688,8 @@ def create_and_dump_syzkaller_description(ioctls_per_fp, workdir: str,
695688
696689 syzkaller_description_types = {}
697690 all_ioctls = []
698- for header_file , ioctls in header_files_to_ioctls .items ():
699- logger .info ('Header file:' )
700- logger .info (header_file )
691+ for _ , ioctls in header_files_to_ioctls .items ():
701692 all_ioctls .extend (ioctls )
702-
703693 types_to_dump = extract_types_of_syzkaller_description (
704694 ioctls , fi_data_dir )
705695 for type_to_dump , type_text in types_to_dump .items ():
@@ -710,7 +700,7 @@ def create_and_dump_syzkaller_description(ioctls_per_fp, workdir: str,
710700 logger .info ('[+] Creating syzkaller description for ' )
711701
712702 syzkaller_description_path = write_syzkaller_description (
713- all_ioctls , syzkaller_description_types , workdir , all_devnodes , '' ,
703+ all_ioctls , syzkaller_description_types , workdir , all_devnodes ,
714704 target_path )
715705 if syzkaller_description_path :
716706 logger .info ('[+] - auto-generated description: %s' ,
0 commit comments