Commit ab5772f7 authored by Oriol Arcas's avatar Oriol Arcas

Do not allow defining the license from CFLAGS or command line

Signed-off-by: default avatarOriol Arcas <oriol@starflownetworks.com>
parent 9aab22ec
......@@ -1550,7 +1550,7 @@ Exception: Failed to load BPF program kretprobe__inet_csk_accept
This error happens when a GPL-only helper is called from a non-GPL BPF program. To fix this error, do not use GPL-only helpers from a proprietary BPF program, or relicense the BPF program under a GPL-compatible license. Check which [BPF helpers](https://github.com/iovisor/bcc/blob/master/docs/kernel-versions.md#helpers) are GPL-only, and what licenses are considered GPL-compatible.
Example calling `bpf_get_stackid()`, a GPL-only BPF helper, from a proprietary program (`cflags=['-DBPF_LICENSE=Proprietary']`):
Example calling `bpf_get_stackid()`, a GPL-only BPF helper, from a proprietary program (`#define BPF_LICENSE Proprietary`):
```
bpf: Failed to load program: Invalid argument
......
......@@ -1279,6 +1279,9 @@ void BFrontendAction::DoMiscWorkAround() {
// CONFIG_CC_STACKPROTECTOR properly based on other configs, so it relieved any bpf
// program (using task_struct, etc.) of patching the below code.
rewriter_->getEditBuffer(rewriter_->getSourceMgr().getMainFileID()).InsertText(0,
"#if defined(BPF_LICENSE)\n"
"#error BPF_LICENSE cannot be specified through cflags\n"
"#endif\n"
"#if !defined(CONFIG_CC_STACKPROTECTOR)\n"
"#if defined(CONFIG_CC_STACKPROTECTOR_AUTO) \\\n"
" || defined(CONFIG_CC_STACKPROTECTOR_REGULAR) \\\n"
......
......@@ -65,51 +65,35 @@ int license_program(struct pt_regs *ctx) {
b = BPF(text=self.gpl_only_text)
self.load_bpf_code(b)
def test_gpl_helper(self):
b = BPF(text=self.gpl_only_text, cflags=["-DBPF_LICENSE=GPL"])
self.load_bpf_code(b)
def test_gpl_helper_macro(self):
b = BPF(text=self.gpl_only_text + self.license('GPL'))
self.load_bpf_code(b)
def test_proprietary(self):
b = BPF(text=self.proprietary_text, cflags=["-DBPF_LICENSE=Proprietary"])
self.load_bpf_code(b)
def test_proprietary_macro(self):
b = BPF(text=self.proprietary_text + self.license('Proprietary'))
self.load_bpf_code(b)
def test_gpl_compatible(self):
b = BPF(text=self.gpl_only_text, cflags=["-DBPF_LICENSE=Dual BSD/GPL"])
self.load_bpf_code(b)
def test_gpl_compatible_macro(self):
b = BPF(text=self.gpl_only_text + self.license('Dual BSD/GPL'))
self.load_bpf_code(b)
def test_proprietary_words(self):
b = BPF(text=self.proprietary_text, cflags=["-DBPF_LICENSE=Proprietary license"])
self.load_bpf_code(b)
def test_proprietary_words_macro(self):
b = BPF(text=self.proprietary_text + self.license('Proprietary license'))
self.load_bpf_code(b)
@unittest.expectedFailure
def test_empty_fail(self):
b = BPF(text=self.gpl_only_text, cflags=["-DBPF_LICENSE="])
def test_cflags_fail(self):
b = BPF(text=self.gpl_only_text, cflags=["-DBPF_LICENSE=GPL"])
self.load_bpf_code(b)
@unittest.expectedFailure
def test_empty_fail_macro(self):
b = BPF(text=self.gpl_only_text + self.license(''))
def test_cflags_macro_fail(self):
b = BPF(text=self.gpl_only_text + self.license('GPL'), cflags=["-DBPF_LICENSE=GPL"])
self.load_bpf_code(b)
@unittest.expectedFailure
def test_proprietary_fail(self):
b = BPF(text=self.gpl_only_text, cflags=["-DBPF_LICENSE=Proprietary license"])
def test_empty_fail_macro(self):
b = BPF(text=self.gpl_only_text + self.license(''))
self.load_bpf_code(b)
@unittest.expectedFailure
......@@ -117,5 +101,10 @@ int license_program(struct pt_regs *ctx) {
b = BPF(text=self.gpl_only_text + self.license('Proprietary license'))
self.load_bpf_code(b)
@unittest.expectedFailure
def test_proprietary_cflags_fail(self):
b = BPF(text=self.proprietary_text, cflags=["-DBPF_LICENSE=Proprietary"])
self.load_bpf_code(b)
if __name__ == "__main__":
unittest.main()
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment