Security update, RHSA-2014:1392-2
[packages/centos6/kernel.git] / check-kabi
1 #!/usr/bin/python
2 #
3 # check-kabi - Red Hat kABI reference checking tool
4 #
5 # We use this script to check against reference Module.kabi files.
6 #
7 # Author: Jon Masters <jcm@redhat.com>
8 # Copyright (C) 2007-2009 Red Hat, Inc.
9 #
10 # This software may be freely redistributed under the terms of the GNU
11 # General Public License (GPL).
12
13 # Changelog:
14
15 # 2009/08/15 - Updated for use in RHEL6.
16 # 2007/06/13 - Initial rewrite in python by Jon Masters.
17
18 __author__ = "Jon Masters <jcm@redhat.com>"
19 __version__ = "2.0"
20 __date__ = "2009/08/15"
21 __copyright__ = "Copyright (C) 2007-2009 Red Hat, Inc"
22 __license__ = "GPL"
23
24 import getopt
25 import os
26 import re
27 import string
28 import sys
29
30 true = 1
31 false = 0
32
33 def load_symvers(symvers,filename):
34         """Load a Module.symvers file."""
35
36         symvers_file = open(filename,"r")
37
38         while true:
39                 in_line = symvers_file.readline()
40                 if in_line == "":
41                         break
42                 if in_line == "\n":
43                         continue
44                 checksum,symbol,directory,type = string.split(in_line)
45
46                 symvers[symbol] = in_line[0:-1]
47
48 def load_kabi(kabi,filename):
49         """Load a Module.kabi file."""
50
51         kabi_file = open(filename,"r")
52
53         while true:
54                 in_line = kabi_file.readline()
55                 if in_line == "":
56                         break
57                 if in_line == "\n":
58                         continue
59                 checksum,symbol,directory,type = string.split(in_line)
60
61                 kabi[symbol] = in_line[0:-1]
62
63 def check_kabi(symvers,kabi):
64         """Check Module.kabi and Module.symvers files."""
65
66         fail=0
67         warn=0
68         changed_symbols=[]
69         moved_symbols=[]
70
71         for symbol in kabi:
72                 abi_hash,abi_sym,abi_dir,abi_type = string.split(kabi[symbol])
73                 if symvers.has_key(symbol):
74                         sym_hash,sym_sym,sym_dir,sym_type = string.split(symvers[symbol])
75                         if abi_hash != sym_hash:
76                                 fail=1
77                                 changed_symbols.append(symbol)
78
79                         if abi_dir != sym_dir:
80                                 warn=1
81                                 moved_symbols.append(symbol)
82                 else:
83                         fail=1
84                         changed_symbols.append(symbol)
85
86         if fail:
87                 print "*** ERROR - ABI BREAKAGE WAS DETECTED ***"
88                 print ""
89                 print "The following symbols have been changed (this will cause an ABI breakage):"
90                 print ""
91                 for symbol in changed_symbols:
92                         print symbol
93                 print ""
94
95         if warn:
96                 print "*** WARNING - ABI SYMBOLS MOVED ***"
97                 print ""
98                 print "The following symbols moved (typically caused by moving a symbol from being"
99                 print "provided by the kernel vmlinux out to a loadable module):"
100                 print ""
101                 for symbol in moved_symbols:
102                         print symbol
103                 print ""
104
105         """Halt the build, if we got errors and/or warnings. In either case,
106            double-checkig is required to avoid introducing / concealing
107            KABI inconsistencies."""
108         if fail or warn:
109                 sys.exit(1)
110         sys.exit(0)
111
112 def usage():
113         print """
114 check-kabi: check Module.kabi and Module.symvers files.
115
116         check-kabi [ -k Module.kabi ] [ -s Module.symvers ]
117
118 """
119
120 if __name__ == "__main__":
121
122         symvers_file = ""
123         kabi_file = ""
124
125         opts, args = getopt.getopt(sys.argv[1:], 'hk:s:')
126
127         for o, v in opts:
128                 if o == "-s":
129                         symvers_file = v
130                 if o == "-h":
131                         usage()
132                         sys.exit(0)
133                 if o == "-k":
134                         kabi_file = v
135         
136         if (symvers_file == "") or (kabi_file == ""):
137                 usage()
138                 sys.exit(1)
139
140         symvers={}
141         kabi={}
142
143         load_symvers(symvers,symvers_file)
144         load_kabi(kabi,kabi_file)
145         check_kabi(symvers,kabi)
146