Received: by 2002:a25:e74b:0:0:0:0:0 with SMTP id e72csp1976736ybh; Tue, 14 Jul 2020 12:06:23 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxeiIb5ohUYXOX+AKFF1y20EK0myUocy2+46azFTjlzcpqchaDD0cIdHNkkXy8XvKWQ7XX3 X-Received: by 2002:a50:b026:: with SMTP id i35mr6090954edd.158.1594753583073; Tue, 14 Jul 2020 12:06:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1594753583; cv=none; d=google.com; s=arc-20160816; b=UOPtF2VmKKCY2J0OqzoDIEjPL4DNfBhjR5eT9vjq9CLdyMflu1QUy4GsJ/AzDe/PNf rn+7SZqX1+hM+RHYbCge+hMJCzKr2lGYk44YYIAWZdO1YnmbaYK9DoZ0pFa91Twf1oD0 XxCaRGPEaPrVYJMCmM5teCQ0wMipSgqZXh5X1W2iXjm2+PjAuhcyrrXyneIiT0a0Q2cU B+/y5BBziXEp2CwaTq7IKOsBn8sGSO5uIGyOShFIORFNC6PHNnTOSHwRMztOIIH+Bf9P F+q4v06MVVnk3x6Bs2pHYEpxShoYpMRj+0rEYAaDJH+sm9PXSJonCwIK6XvXLqKTuq3J 2NNg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=q+WBwjYHZqqv7CFeBdFr8wipiMwUBHR/2D55v7PgfaI=; b=PpmNGari9IshxR7bRK9HCcW1O21G7ZkvWZ1OYVdCUZnNAW1NNEWuXlJcLZAeeNDZaQ GogOJ8qZ7scH+Q86kBTNZDVvKMXnvowdGN8j/wfqA1eJ9bYyMcTm+SpE3bDi12VXSAYM iJ3Dd1Ngbd8747OPj+vy1LG8SA7EkfoJjsnTZsYx4HvUMwIGhKfcKM8A2r/zRqA2XmT+ Xcm2+If20AF7YnquLsSbc/lx+P5X/HblfejGpsX7fedhvXGcU4KqudbNrsnN988rOpjw iZoDas6mX3PAlDkeqhkNou6lXv0P/iJb1Ep6OUTWFSzvRj8uthUHt7UcU8QPBFefGQtU WSrg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=B2X1Wb1g; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id g14si12107617edv.102.2020.07.14.12.05.59; Tue, 14 Jul 2020 12:06:23 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=B2X1Wb1g; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730889AbgGNSzl (ORCPT + 99 others); Tue, 14 Jul 2020 14:55:41 -0400 Received: from mail.kernel.org ([198.145.29.99]:53326 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730886AbgGNSzg (ORCPT ); Tue, 14 Jul 2020 14:55:36 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id B1D9A21D79; Tue, 14 Jul 2020 18:55:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1594752935; bh=/OB5+buJ/dYANcHnH4H5AnXekZPVzzEHTMS/vT95zmQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=B2X1Wb1g5VmPC6CCbfBREeo2ALgk2YO8ZLUWL763Ox/qu7eGjetoTY9z3Nub/YKen 9jTVPo/JW5gz5mStiEWXljEVDn91+C9hpx8SSXfexT+kwBaDnynjocUTv4p4UdHYfG OUUA6okiLTyD1dyxuzXvjt/vK+IOx47G6ZqdJhZA= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, John Fastabend , Daniel Borkmann , Andrii Nakryiko , Sasha Levin Subject: [PATCH 5.7 055/166] bpf: Do not allow btf_ctx_access with __int128 types Date: Tue, 14 Jul 2020 20:43:40 +0200 Message-Id: <20200714184118.509799543@linuxfoundation.org> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200714184115.844176932@linuxfoundation.org> References: <20200714184115.844176932@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: John Fastabend [ Upstream commit a9b59159d338d414acaa8e2f569d129d51c76452 ] To ensure btf_ctx_access() is safe the verifier checks that the BTF arg type is an int, enum, or pointer. When the function does the BTF arg lookup it uses the calculation 'arg = off / 8' using the fact that registers are 8B. This requires that the first arg is in the first reg, the second in the second, and so on. However, for __int128 the arg will consume two registers by default LLVM implementation. So this will cause the arg layout assumed by the 'arg = off / 8' calculation to be incorrect. Because __int128 is uncommon this patch applies the easiest fix and will force int types to be sizeof(u64) or smaller so that they will fit in a single register. v2: remove unneeded parens per Andrii's feedback Fixes: 9e15db66136a1 ("bpf: Implement accurate raw_tp context access via BTF") Signed-off-by: John Fastabend Signed-off-by: Daniel Borkmann Acked-by: Andrii Nakryiko Link: https://lore.kernel.org/bpf/159303723962.11287.13309537171132420717.stgit@john-Precision-5820-Tower Signed-off-by: Sasha Levin --- include/linux/btf.h | 5 +++++ kernel/bpf/btf.c | 4 ++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/include/linux/btf.h b/include/linux/btf.h index 5c1ea99b480fa..8b81fbb4497cf 100644 --- a/include/linux/btf.h +++ b/include/linux/btf.h @@ -82,6 +82,11 @@ static inline bool btf_type_is_int(const struct btf_type *t) return BTF_INFO_KIND(t->info) == BTF_KIND_INT; } +static inline bool btf_type_is_small_int(const struct btf_type *t) +{ + return btf_type_is_int(t) && t->size <= sizeof(u64); +} + static inline bool btf_type_is_enum(const struct btf_type *t) { return BTF_INFO_KIND(t->info) == BTF_KIND_ENUM; diff --git a/kernel/bpf/btf.c b/kernel/bpf/btf.c index d65c6912bdaf6..d1f5d428c9fe2 100644 --- a/kernel/bpf/btf.c +++ b/kernel/bpf/btf.c @@ -3744,7 +3744,7 @@ bool btf_ctx_access(int off, int size, enum bpf_access_type type, return false; t = btf_type_skip_modifiers(btf, t->type, NULL); - if (!btf_type_is_int(t)) { + if (!btf_type_is_small_int(t)) { bpf_log(log, "ret type %s not allowed for fmod_ret\n", btf_kind_str[BTF_INFO_KIND(t->info)]); @@ -3766,7 +3766,7 @@ bool btf_ctx_access(int off, int size, enum bpf_access_type type, /* skip modifiers */ while (btf_type_is_modifier(t)) t = btf_type_by_id(btf, t->type); - if (btf_type_is_int(t) || btf_type_is_enum(t)) + if (btf_type_is_small_int(t) || btf_type_is_enum(t)) /* accessing a scalar */ return true; if (!btf_type_is_ptr(t)) { -- 2.25.1