21
- And how it can help fight linux kernel ABI breakages Samikshan Bairagya By, {#,@}samikshan Introducing 'spartakus' Content available under Attribution-ShareAlike 3.0 Unported (CC BY-SA 3.0)

Introduction to spartakus and how it can help fight linux kernel ABI breakages

Embed Size (px)

Citation preview

Page 1: Introduction to spartakus and how it can help fight linux kernel ABI breakages

- And how it can help fight linux kernel ABI breakages

Samikshan BairagyaBy,

{#,@}samikshan

Introducing 'spartakus'

Content available under Attribution-ShareAlike 3.0 Unported (CC BY-SA 3.0)

Page 2: Introduction to spartakus and how it can help fight linux kernel ABI breakages

Topics to cover

● What is kernel ABI● Why does kABI matter● How to track kABI breakages● Static code analysis using genksyms

● Issues with genksyms● Semantic code analysis using sparse (spartakus)

Page 3: Introduction to spartakus and how it can help fight linux kernel ABI breakages

What is ABI?

● ABI == Application Binary Interface● Like API, but at binary level● Interface for application to use external library,

OS at binary level.● If ABI does not change, applications compiled

against that ABI do not need recompilation

Page 4: Introduction to spartakus and how it can help fight linux kernel ABI breakages

Linux kernel ABI?

Binary interface exported by linux kernel and accompanying kernel modules

Page 5: Introduction to spartakus and how it can help fight linux kernel ABI breakages

EXPORT_SYMBOL

~/r/k/linux-3.14> grep -Rn "EXPORT_SYMBOL" .

./kernel/async.c:303:EXPORT_SYMBOL_GPL(async_synchronize_cookie_domain);

./kernel/async.c:316:EXPORT_SYMBOL_GPL(async_synchronize_cookie);

./kernel/gcov/base.c:52:EXPORT_SYMBOL(__gcov_init);

./kernel/gcov/base.c:62:EXPORT_SYMBOL(__gcov_flush);

./kernel/gcov/base.c:68:EXPORT_SYMBOL(__gcov_merge_add);

./kernel/gcov/base.c:74:EXPORT_SYMBOL(__gcov_merge_single);

./kernel/gcov/base.c:80:EXPORT_SYMBOL(__gcov_merge_delta);

./kernel/gcov/base.c:86:EXPORT_SYMBOL(__gcov_merge_ior);

./kernel/tracepoint.c:395:EXPORT_SYMBOL_GPL(tracepoint_probe_register);

./kernel/tracepoint.c:439:EXPORT_SYMBOL_GPL(tracepoint_probe_unregister);

Page 6: Introduction to spartakus and how it can help fight linux kernel ABI breakages

Why strive for kABI stability

● kABI instability does not provide a welcoming third party environment to the hardware manufacturers

● Stable kABI means– Third party modules don't break and recompilation

against the changed ABI won't be needed– Specially important for enterprise Linux vendors

Page 7: Introduction to spartakus and how it can help fight linux kernel ABI breakages

How to track kernel ABI

● ABI checksum information (modversions) for exported kernel symbols

– Information stored in Module.symvers file– Generated during kernel build process using genksyms

Page 8: Introduction to spartakus and how it can help fight linux kernel ABI breakages

Module.symvers

$ cat /usr/src/kernels/4.0.4-303.fc22.x86_64/Module.symvers

0x00000000 iscsi_host_add drivers/scsi/libiscsi EXPORT_SYMBOL_GPL

0x00000000 mpt_deregister drivers/message/fusion/mptbase EXPORT_SYMBOL

0x00000000 tm6000_set_reg_mask drivers/media/usb/tm6000/tm6000 EXPORT_SYMBOL_GPL

0x00000000 kvm_get_cs_db_l_bits arch/x86/kvm/kvm EXPORT_SYMBOL_GPL

0x00000000 ipv6_chk_custom_prefix vmlinux EXPORT_SYMBOL

0x00000000 sata_pmp_error_handler vmlinux EXPORT_SYMBOL_GPL

0x00000000 __cleancache_invalidate_page vmlinux EXPORT_SYMBOL

0x00000000 pcmcia_reset_card vmlinux EXPORT_SYMBOL

0x00000000 unregister_vt_notifier vmlinux EXPORT_SYMBOL_GPL

0x00000000 kmem_cache_alloc vmlinux EXPORT_SYMBOL

0x00000000 replace_page_cache_page vmlinux EXPORT_SYMBOL_GPL

0x00000000 __cond_resched_softirq vmlinux EXPORT_SYMBOL

Page 9: Introduction to spartakus and how it can help fight linux kernel ABI breakages

genksyms

● Generates checksums for exported kernel symbols during build process

● Static code analysis● Part of the linux kernel source code

● tools/genksyms/

Page 10: Introduction to spartakus and how it can help fight linux kernel ABI breakages

genksyms - issues

Strict string processing of kernel symbol definition prototypes leads to false positives at times

Page 11: Introduction to spartakus and how it can help fight linux kernel ABI breakages

genksyms generates different checksums for structs/unions for declarations which are semantically same

genksyms – issues (contd)

Page 12: Introduction to spartakus and how it can help fight linux kernel ABI breakages

genksyms – issues (contd)

● 2 semantically same struct declarations should not lead to a change in kABI

● But due to strict string processing in genksyms, checksums generated for these 2 declarations are different

struct list_head {

struct list_head *next, *prev;

};

struct list_head {

struct list_head *next;

struct list_head *prev;

};

Page 13: Introduction to spartakus and how it can help fight linux kernel ABI breakages

Misleading checksums generated for variables specified as unsigned/signed of no particular data type.

● Both declarations above are semantically similar● genksyms fails to identify this

genksyms – issues (contd)

'unsigned foo' and 'unsigned int foo'

Page 14: Introduction to spartakus and how it can help fight linux kernel ABI breakages

Possible solution?

spartakus - Using sparse for semantic processing of linux source code

Page 15: Introduction to spartakus and how it can help fight linux kernel ABI breakages

Using spartakus to generate checksums through semantic processing of source code eliminates such issues

● ‘unsigned foo’ is converted to ‘unsigned int foo’ and then processed to get the corresponding checksum

● Semantically similar struct/union declarations are treated as same and different checksums are not generated

Page 16: Introduction to spartakus and how it can help fight linux kernel ABI breakages

Wait, but what is spartakus?● A fork of sparse

– 'semantic parser of source files– creates a semantic parse tree for further

analysis● Provides additional binary 'check_kabi'

– Generates checksums for exported kernel symbols like genksyms during kernel build time

Page 17: Introduction to spartakus and how it can help fight linux kernel ABI breakages

Is spartakus ready yet?

Page 18: Introduction to spartakus and how it can help fight linux kernel ABI breakages

$ git clone https://github.com/samikshan/spartakus.git

– Contribute– License: GPLv2

Page 19: Introduction to spartakus and how it can help fight linux kernel ABI breakages

Some URLs for reference:● Sparse:

– http://kernelnewbies.org/Sparse● Kernel ABI

– http://kernelnewbies.org/ABI– http://www.jonmasters.org/blog/2007/06/16/ludi

crously-technical-kernel-abi-tracking/

Page 20: Introduction to spartakus and how it can help fight linux kernel ABI breakages

Questions?

Content available under Attribution-ShareAlike 3.0 Unported (CC BY-SA 3.0)

[email protected]:

Page 21: Introduction to spartakus and how it can help fight linux kernel ABI breakages

Thanks