Skip to content

Commit

Permalink
fix(userspace/libscap): read eBPF probe license from ELF and use it f…
Browse files Browse the repository at this point in the history
…or loading tracepoint BPF programs

Signed-off-by: Leonardo Di Donato <[email protected]>
  • Loading branch information
leodido committed May 17, 2021
1 parent fdfb059 commit 3a30072
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
10 changes: 9 additions & 1 deletion userspace/libscap/scap_bpf.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

#include <stdio.h>
#include <stdlib.h>
#include <sys/mman.h>
Expand Down Expand Up @@ -61,6 +61,8 @@ static const int BUF_SIZE_PAGES = 2048;

static const int BPF_LOG_SIZE = 1 << 18;

static char* license;

#define FILLER_NAME_FN(x) #x,
static const char *g_filler_names[PPM_FILLER_MAX] = {
FILLER_LIST_MAPPER(FILLER_NAME_FN)
Expand Down Expand Up @@ -152,6 +154,7 @@ static int bpf_load_program(const struct bpf_insn *insns,
attr.prog_type = type;
attr.insn_cnt = (uint32_t) insns_cnt;
attr.insns = (unsigned long) insns;
attr.license = (unsigned long) license;
attr.log_buf = (unsigned long) NULL;
attr.log_size = 0;
attr.log_level = 0;
Expand Down Expand Up @@ -614,6 +617,11 @@ static int32_t load_bpf_file(scap_t *handle, const char *path)
goto cleanup;
}
}
else if(strcmp(shname, "license") == 0)
{
license = data->d_buf;
snprintf(handle->m_lasterr, SCAP_LASTERR_SIZE, "BPF probe license is %s", license);
}
}

if(!symbols)
Expand Down
2 changes: 1 addition & 1 deletion userspace/libscap/scap_bpf.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

#ifndef _SCAP_BPF_H
#define _SCAP_BPF_H

Expand Down

0 comments on commit 3a30072

Please sign in to comment.