2021-04-28 10:21:12

by Liu, Congyu

[permalink] [raw]
Subject: PROBLEM: potential information leakage in /proc/net/ptype

Hi,

When a process in network namespace A creates a packet socket without binding to any interface, a process in network namespace B can observe the a `packet_rcv` entry being registered by reading /proc/net/ptype, thus it can infer information about the processes in namespace A.

By looking at the code, it looks like hook function `packet_rcv` is namespace aware and only works in one net namespace: it only intercepts packets from the devices inside the network namespace where the packet socket is created. However, the `packet_recv` ptype entry can be seen in all namespaces via /proc/net/ptype. Though minor, this looks like an information leakage.

/proc/net/ptype seems to be the root cause: it does not filter those ptype entries that do not bind to any interface. But I have also noticed that there were efforts to prevent /proc/net/ptype from leaking net namespace information, e.g. commit 2feb27d. So I am wondering if this problem is an information leakage bug or deliberate by design? If the latter, what is the reasoning for this?

Thanks for your time and patience!


Thanks,
Congyu Liu


Code:
#define _GNU_SOURCE
#include <sched.h>
#include <sys/wait.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <errno.h>
#include <sys/socket.h>
#define errExit(msg)??? do { perror(msg); exit(EXIT_FAILURE); \
??????????????????????????? } while (0)
int main() {
??? char x;
??? int pipe_fd[2];
??? if (pipe(pipe_fd) < 0) {
??????? errExit("pipe");
??? }
??? int pid = fork();
??? if (pid < 0) {
??????? errExit("fork");
??? }
??? if (pid == 0) {
??????? close(pipe_fd[1]);
??????? unshare(CLONE_NEWNET);
??????? if (read(pipe_fd[0], &x, 1) < 0) {
??????????? errExit("read d");
??????? }
??????? system("cat /proc/net/ptype");
??????? return 0;
??? }
??? close(pipe_fd[0]);
??? unshare(CLONE_NEWNET);
??? socket(AF_PACKET, SOCK_RAW, 768);
??? if (write(pipe_fd[1], &x, 1) < 0) {
??????? errExit("write");
??? }
??? wait(NULL);
??? return 0;
}