Re: [PATCH bpf-next v3 3/9] bpf: Add bpf_sock_addr_set() to allow writing sockaddr len from bpf

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 8/29/23 3:18 AM, Daan De Meyer wrote:
+__bpf_kfunc int bpf_sock_addr_set_addr(struct bpf_sock_addr_kern *sa_kern,
+				       const u8 *addr, u32 addrlen__sz)
+{
+	struct sockaddr *sa = sa_kern->uaddr;
+	struct sockaddr_in *sa4;
+	struct sockaddr_in6 *sa6;
+	struct sockaddr_un *un;
+
+	switch (sa->sa_family) {

The sa_family could be AF_UNSPEC here for inet addr (eg. take a look at __inet_bind checking AF_UNSPEC). Test the sa_kern->sk->sk_family instead.

+	case AF_INET:
+		if (addrlen__sz != 4)
+			return -EINVAL;
+		sa4 = (struct sockaddr_in *)sa;
+		sa4->sin_addr.s_addr = *(__be32 *)addr;
+		break;
+	case AF_INET6:
+		if (addrlen__sz != 16)
+			return -EINVAL;
+		sa6 = (struct sockaddr_in6 *)sa;
+		memcpy(sa6->sin6_addr.s6_addr, addr, 16);
+		break;
+	default:
+		WARN_ON_ONCE(1);

The above switch case will test sk_family instead, so this WARN should never happen and should be removed.

+		return -EINVAL;
+	}
+
+	return 0;
+}
  __diag_pop();





[Index of Archives]     [Linux Samsung SoC]     [Linux Rockchip SoC]     [Linux Actions SoC]     [Linux for Synopsys ARC Processors]     [Linux NFS]     [Linux NILFS]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]


  Powered by Linux