From patchwork Mon Jul 29 14:42:48 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Will Hawkins X-Patchwork-Id: 1966068 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=obs-cr.20230601.gappssmtp.com header.i=@obs-cr.20230601.gappssmtp.com header.a=rsa-sha256 header.s=20230601 header.b=ZDneF/rc; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4WXh1Q3rlxz1ybY for ; Tue, 30 Jul 2024 00:43:18 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 08FF9385840E for ; Mon, 29 Jul 2024 14:43:17 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-qv1-xf2d.google.com (mail-qv1-xf2d.google.com [IPv6:2607:f8b0:4864:20::f2d]) by sourceware.org (Postfix) with ESMTPS id 011A03858D37 for ; Mon, 29 Jul 2024 14:42:54 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 011A03858D37 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=obs.cr Authentication-Results: sourceware.org; spf=none smtp.mailfrom=obs.cr ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 011A03858D37 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::f2d ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1722264176; cv=none; b=XJeJbcBTXZ6EWHqxFC83rGWqqC9DkMBGS1+qs2lIrSD1SHsAQcmQi0TySrekwuCGJFvk+gt6/d1HzAbK+57m7DSEUvOLIO6MLmxqeN6rHf9mjMig/B/s2q/qN0NYXeuAG09z8/Qk0LAF9htZYW0q+ZIYNHNoVq6fLUEqWImudIo= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1722264176; c=relaxed/simple; bh=ngFKuk5dpZwpKXPHRzcoNlNhGvD2F6qyBG9qoscuHKo=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=ETGh2S9tDxskWpICvcYDt2YUW0r8OXG6b985arzUytdav9r+lnzoeLt0fc+tdzHQQIY8FJ/ZVJFwm29ByvQ4/Gk5Nqvfgiz2Ze15eXRA2i21QN34Ua0b7Lsg+2m8g4tKmJJwHczLu1edt+NLJAhcaYOgA2Itfqfv7ZIx2HgAyIQ= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-qv1-xf2d.google.com with SMTP id 6a1803df08f44-6b7aed340daso21431776d6.3 for ; Mon, 29 Jul 2024 07:42:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=obs-cr.20230601.gappssmtp.com; s=20230601; t=1722264173; x=1722868973; darn=gcc.gnu.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=Mdm4bm2EVi6tpU3rFoaay2HtGpHCwsD5KK4H3E/+IxU=; b=ZDneF/rczZlwWSI464P0Lz0DModtlOPEZiyg+xIuXOI1dqQHtXfvK061dge7pplwYZ DRF17j7p4Ra0LOUvjJO8kHt3zQch0o6woV0C4Tg4mch6w6hasLFVDU77TE3C8AO4loWo bBPOAdxAfvu3p8OqFSdUl9gpEVDPjtphPsI8jlfg1b3CLLBtnZ5+DXVEQAR1ZGgA6I8k ISnSov6fyRkHjeU2SS7bgBq+/J7CdIbqy8EKILsN5f3eaQrKXNSLH6qEzWXHlm5Efq0U mRAdPKSI2eNaZjGgk+dLe2o9GoKvyeelALP4EWq1lm0dPI2Lh2SVIivMFG/C/jzH2KFx JXqQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722264173; x=1722868973; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=Mdm4bm2EVi6tpU3rFoaay2HtGpHCwsD5KK4H3E/+IxU=; b=PbO15a1h2Tt08fc78/Omrxo5QpCKXTiqx0WuMAfGoUDIXRWD8Mw/PSCb1oTXW+jxEY FI5/6s00vFMiyp3ue3AUZq2T5HKmE68NcszDTbhEyTV3sJaEIhuiPEf3VQE74aQaMJ7Y bY+vPJloj/dTrHPbNqpcgYvODXEkaMmxD7IE6Z8EuZC+/UedsY0/gvE/RavPbA3NMdHt smmwOB7bIAX4biu2r0ADm8pVtrF1aOR3bCJ27ny5FVRISpdZT8gxPR3womzylCSkqRi7 +pu8R36tVbdF2GgCXNVJA6WvPG7//R0RTLB1jsWotDrh+ql2S0UaH3mieWuqgiODLzQ9 PdgA== X-Gm-Message-State: AOJu0Yx8cUC7H+SiaLV94voc44A67Iyp/Pj7AHJ4bO9c418yrkovJtAD NH/xnsakU3A6f4Sq0VEyv4Aj+6zMhSLme/VzEwG5FxqtxB7PMK2I8rDnVhsiQ4HVNGvmuIC2SqF / X-Google-Smtp-Source: AGHT+IHrcCcU2/TYKbCCeTB9PkIUHdeiXESb+BvFTY3/LoARTBbTFfJkJz9tZ/GNqkqOy6y49TNagA== X-Received: by 2002:a05:6214:e48:b0:6b5:dcda:bada with SMTP id 6a1803df08f44-6bb55adc0b1mr107732336d6.55.1722264173070; Mon, 29 Jul 2024 07:42:53 -0700 (PDT) Received: from ininer.rhod.uc.edu ([129.137.96.15]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-6bb3fac396esm52534556d6.111.2024.07.29.07.42.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 29 Jul 2024 07:42:52 -0700 (PDT) From: Will Hawkins To: gcc-patches@gcc.gnu.org Cc: Will Hawkins Subject: [PATCH] btf: Protect BTF_KIND_INFO against invalid kind Date: Mon, 29 Jul 2024 10:42:48 -0400 Message-ID: <20240729144248.911058-1-hawkinsw@obs.cr> X-Mailer: git-send-email 2.45.2 MIME-Version: 1.0 X-Spam-Status: No, score=-9.7 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org If the user provides a kind value that is more than 5 bits, the BTF_KIND_INFO macro would emit incorrect values for info (by clobbering values of the kind flag). Tested on x86_64-redhat-linux. include/ChangeLog: * btf.h (BTF_TYPE_INFO): Protect against user providing invalid kind. Signed-off-by: Will Hawkins --- Notes: I have a small out-of-tree test but was not sure whether a) it should be included and/or b) where it should be included. If you would like me to include it, please just let me know where it should go! include/btf.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/btf.h b/include/btf.h index 3f45ffb0b6b..0c3e1a1cf51 100644 --- a/include/btf.h +++ b/include/btf.h @@ -82,7 +82,7 @@ struct btf_type }; }; -/* The folloing macros access the information encoded in btf_type.info. */ +/* The following macros access the information encoded in btf_type.info. */ /* Type kind. See below. */ #define BTF_INFO_KIND(info) (((info) >> 24) & 0x1f) /* Number of entries of variable length data following certain type kinds. @@ -95,7 +95,7 @@ struct btf_type /* Encoding for struct btf_type.info. */ #define BTF_TYPE_INFO(kind, kflag, vlen) \ - ((((kflag) ? 1 : 0 ) << 31) | ((kind) << 24) | ((vlen) & 0xffff)) + ((((kflag) ? 1 : 0 ) << 31) | ((kind & 0x1f) << 24) | ((vlen) & 0xffff)) #define BTF_KIND_UNKN 0 /* Unknown or invalid. */ #define BTF_KIND_INT 1 /* Integer. */