From patchwork Wed Nov 6 14:39:22 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Anton Moryakov X-Patchwork-Id: 100407 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 6F5583858C52 for ; Wed, 6 Nov 2024 14:39:40 +0000 (GMT) X-Original-To: elfutils-devel@sourceware.org Delivered-To: elfutils-devel@sourceware.org Received: from mail-lf1-x12c.google.com (mail-lf1-x12c.google.com [IPv6:2a00:1450:4864:20::12c]) by sourceware.org (Postfix) with ESMTPS id A83383858D20 for ; Wed, 6 Nov 2024 14:39:28 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org A83383858D20 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org A83383858D20 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::12c ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1730903971; cv=none; b=MPqzldeHbKDEWSXROIfJkJH0u/BNP/qv2FVz0xHqHRRzbl+pe/T8KkCtzgTUax/wOUuNVLClTYdUuRkfk+JgVLi75VL0EhOABKau1ga0UzhWnDVdes8uAV5MZQqsIl9tM8Yo9i2syOdGnf6f/6bv9oqbHGvIAjFiSTODWNKqkrc= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1730903971; c=relaxed/simple; bh=sBXHjzxVINSJgES6QJsQQwX2FZT8sWsYKwC0tsPoCIo=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=BN+MFCwkxP57x+ZsX48x6CjslpeMEBBIA02ufBi7hFbd++I3Dth6n+mkNzFWtGR5OD812BH1E0zydgjSkADNF6blY4vo/Mjho+HjZ216GKhalkQrZ+gmFiQuPwmPqWXa9oRfjyr07hgfEKeJeNNlU4tKZISDc83QG+OfvfGm4IQ= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-lf1-x12c.google.com with SMTP id 2adb3069b0e04-539f4d8ef66so8427119e87.1 for ; Wed, 06 Nov 2024 06:39:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1730903967; x=1731508767; darn=sourceware.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=duWYkpND2blmZDvsfHlrsDH7Kkl/8su6oPzsP3qf6eQ=; b=HD16CkIsbctWy/BpXszv+XQhdlrecowfIJlrZGpsAj27+jqQYX1L7l1jcp85hj+b8j SvLUBIzg8mK5EeH4iTJ8y6FS/N+spwPcpy2cZcKK1zw3pt+TpuodoQcE4OuVScjla0VD UZw+B1YgFpQ4/G1vlkJwinGAMAQjQBhOkVopH2+44VeLS5A8fICeCR+WcGk8ofpz8vNA mupbcIGYIVvAom8NlleUzSQekKawc51jlMldgkF6PZ/Kh53dSljbkafCcf/cVbTsRK9g e1+aKm4xv++uvcXbQS7kheQGs5qLHIwsBdPIHEuBykUuCZPPYHJ1pT70Tu88MEUBnCbk iR0g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730903967; x=1731508767; 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=duWYkpND2blmZDvsfHlrsDH7Kkl/8su6oPzsP3qf6eQ=; b=hwY2fzEQRnkmyzRqPhx7R4KtL8+vEEJvXKRnmDibN+A7wMHyxWb1bb6X9JzGCPSazp zaHQmhkvKlmZWsrkb/WsWF5pfJ2ykTR7Km07VOHamdXmN7JCUcr36H2c7cLalK2ZBw2M 3VU1OueppsbinHZ3zhwpq1BfjJdyoZWd6zEDOv4lpiL0XV7BWp235FWuHE5Y3ITQCdDi B2+wXytZHe4dF1NHhuQnEEfolVS4MoqKOgRvE24b3UP2DvKRnX/mjl3Adfmx4o781LvP ZM8rQDfO/2bBC0mGPrZCQxQHnrnbnDfSIudeLmrDwyI/2s7qOt0GPJZmHA6qwbP8NwnE gk0A== X-Gm-Message-State: AOJu0Yw8W5gO6D16B2UpUN4TG1+Xw9b6xdIG5AZv1mWUJOzzlNI5M623 hrose5gUnZycBPC3Vm/6zs/L25qpqv0BkKOPrrt56XS0hKWFf3fNk/tzbuom X-Google-Smtp-Source: AGHT+IFcLyFkCvcr70wQOPLgSCRv28SFuMWmw/v0y6lrS1uDg35j7/S7msu4421XH8et266LGEXYug== X-Received: by 2002:a05:6512:684:b0:539:ffb5:8d2c with SMTP id 2adb3069b0e04-53b3490f2eemr19635811e87.30.1730903966466; Wed, 06 Nov 2024 06:39:26 -0800 (PST) Received: from astra-student.rasu.local (109-252-122-202.nat.spd-mgts.ru. [109.252.122.202]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-53c7bcce6d9sm2467935e87.120.2024.11.06.06.39.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Nov 2024 06:39:26 -0800 (PST) From: Anton Moryakov To: elfutils-devel@sourceware.org Cc: AntonMoryakov Subject: [PATCH] FIX #90: STRING_OVERFLOW in sparc_attrs.c Date: Wed, 6 Nov 2024 17:39:22 +0300 Message-Id: <20241106143922.83952-1-ant.v.moryakov@gmail.com> X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 X-Spam-Status: No, score=-8.9 required=5.0 tests=BAYES_00, BODY_8BITS, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_BARRACUDACENTRAL, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, 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: elfutils-devel@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Elfutils-devel mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: elfutils-devel-bounces~patchwork=sourceware.org@sourceware.org From: AntonMoryakov first report of the static analyzer: A string is copied into the buffer 's' of size 577 without checking its length first at sparc_attrs.c:95. Corrections explained: Added static_assert to check the size of the name buffer at compile time. This static_assert will assert that the buffer is large enough to hold all possible values, without changing the rest of the logic. Found by RASY JSC signed-off-by: Anton Moryakov diff --git a/elfutils/backends/sparc_attrs.c b/elfutils/backends/sparc_attrs.c index 974e8fb..8cbf8cb 100644 --- a/elfutils/backends/sparc_attrs.c +++ b/elfutils/backends/sparc_attrs.c @@ -32,10 +32,14 @@ #include #include +#include #define BACKEND sparc_ #include "libebl_CPU.h" +#define NAME_MAX_SIZE (32 * 17 + 32 + 1) // новый код +static_assert(NAME_MAX_SIZE == (32 * 17 + 32 + 1), "Buffer size for 'name' is insufficient"); + bool sparc_check_object_attribute (Ebl *ebl __attribute__ ((unused)), const char *vendor, int tag, uint64_t value, @@ -63,7 +67,7 @@ sparc_check_object_attribute (Ebl *ebl __attribute__ ((unused)), /* NAME should be big enough to hold any possible comma-separated list (no repetitions allowed) of attribute names from one of the arrays above. */ - static char name[32*17+32+1]; + static char name[NAME_MAX_SIZE]; name[0] = '\0'; if (!strcmp (vendor, "gnu"))