Message ID | 20231123153147.537151-1-vvvvvv@google.com |
---|---|
State | Committed |
Headers |
Return-Path: <elfutils-devel-bounces+patchwork=sourceware.org@sourceware.org> 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 85EC3385DC2E for <patchwork@sourceware.org>; Thu, 23 Nov 2023 15:32:07 +0000 (GMT) X-Original-To: elfutils-devel@sourceware.org Delivered-To: elfutils-devel@sourceware.org Received: from mail-yb1-xb49.google.com (mail-yb1-xb49.google.com [IPv6:2607:f8b0:4864:20::b49]) by sourceware.org (Postfix) with ESMTPS id 6486C3858C2B for <elfutils-devel@sourceware.org>; Thu, 23 Nov 2023 15:31:59 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 6486C3858C2B Authentication-Results: sourceware.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=flex--vvvvvv.bounces.google.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 6486C3858C2B Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::b49 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1700753521; cv=none; b=qWJFQApCNW79Jv7Rt9Af5pZHBB5dXrnsIhN8yOFhElYGjcJsosoYitzuAdtMZr6+YsJRGTe2rUxsv3gGXoi186r0NJn20k06R0qv667Jzk+rcBomCa9Taf4RLNmFeYWNXttYEsEDngCXHKllE0CHOH/x8Zzbk4ts0IvX9+C27Es= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1700753521; c=relaxed/simple; bh=6JYUQEVkUWt04y7niabG9YzLmkQUmQllasxBVu01yX4=; h=DKIM-Signature:Date:Mime-Version:Message-ID:Subject:From:To; b=Rey9/SFBGo2vKePhOV3CD4a2wmsrCgRfj9zAORytgeoJC08lLNYtpBCkjnxTxQIVh8SJ5XJiG5jdU6J9BZecw00n7+nzNTMsBucix46zXoCAuMzwVrbpIKJZeKPKtrSwWawmdThxjXnfYrLXppy4maZmFHkTJJ4EAb9FNld/zk0= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-yb1-xb49.google.com with SMTP id 3f1490d57ef6-d9cb10a5d44so814363276.0 for <elfutils-devel@sourceware.org>; Thu, 23 Nov 2023 07:31:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1700753518; x=1701358318; darn=sourceware.org; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=IeNC0zYVC5MBRg0LJl73NxgMrUz9jYYoPaq0RdObkTA=; b=3FVeXg/qpeFGY4IeKxFQeZvL4/JwRg0SQXW2nkZG4gGT83ld7/9JR9ak8DIQcalfjI GXvidAJa9JXs9x6XG4iG54zgd/kZjqiEMjKoLqYsKZG5GPs0+OkEED5SiFAsM4X2A7qz Eq0mgivhPIBsAueFYH7I6/0ug/dU0rG5TS6uvG3Nu1LryWao0/9tzvMOLojIV+wdFBud y7vZgTP0UxQNE6eHTBQFbUOls5qjANecS16Inb2sTn3291JlVSYfdOWRYZT6/ZxjIyo3 9czCiOVDD1KRu9cM+gCvNEac1MxFmaLJsG9mx/20go7wPXKtBmz0/Gowkr0abUCfx1wV GpCg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1700753518; x=1701358318; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=IeNC0zYVC5MBRg0LJl73NxgMrUz9jYYoPaq0RdObkTA=; b=HcC6zqVbf+pUqgNw0xaL2PRqT/JIFOq1EXX6giIGi8YVCijrKbCC8J8gNRT+s9e1qb hklAv9DcYWAb4yqJ/Uf1touK4KXa3O5tKmPZrjhv9cn2nrOQfLCkOymQk4NeiUAO7X7f iLgHnoi5apcLDWPY01X0Gi9LLf/meAJml4glyXoF4k/hDFQA3wUYLm2azuUvLl01QbKf iYVmwMHBy66WxeeY26yrwNumIBbQ1flBKYmZaMhHrvkAL8tz0f2vrLLLU9vRNuXP+vjp LS4c4K5s7BTS2MeSreROKdJkkKSTgC4Qoie2bQG6a4gsZqW/aM18s1GJ179X5U8Remyc E86Q== X-Gm-Message-State: AOJu0Yzd1F3YFS3SL2w4ZI6S7g/0W92uhtynrZ3i8P6ObZsziYSYqQRI iFJQakcR98imgplW/5tuZlXlloDW6yF6r432dVte0lfgDB9RkhkMeZgg8LewD8uUKg1qX1+sA/c bCQor7D6aMFBBGosxwE9apwseCvlIcwqqGLQmuUMoaZPKDAYAp8zOXpBFbLsMqlHeAu/HMrY= X-Google-Smtp-Source: AGHT+IF3E+MVABWB18VRI5YieZ3XPyrKY2WRS6n3aRVmYU3rK5TJCOgA2s5erL+UoTll6BAv+HVEcMUhPDM= X-Received: from vvvvvv-dev.c.googlers.com ([fda3:e722:ac3:cc00:28:9cb1:c0a8:472]) (user=vvvvvv job=sendgmr) by 2002:a25:cf8a:0:b0:d9a:4421:6ec5 with SMTP id f132-20020a25cf8a000000b00d9a44216ec5mr188894ybg.3.1700753518606; Thu, 23 Nov 2023 07:31:58 -0800 (PST) Date: Thu, 23 Nov 2023 15:31:47 +0000 Mime-Version: 1.0 X-Mailer: git-send-email 2.43.0.rc1.413.gea7ed67945-goog Message-ID: <20231123153147.537151-1-vvvvvv@google.com> Subject: [PATCH] libelf: check decompressed ZSTD size From: Aleksei Vetrov <vvvvvv@google.com> To: elfutils-devel@sourceware.org Cc: kernel-team@android.com, maennich@google.com, vvvvvv@google.com Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-19.4 required=5.0 tests=BAYES_00, DKIMWL_WL_MED, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, HK_RANDOM_FROM, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE, USER_IN_DEF_DKIM_WL 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 <elfutils-devel.sourceware.org> List-Unsubscribe: <https://sourceware.org/mailman/options/elfutils-devel>, <mailto:elfutils-devel-request@sourceware.org?subject=unsubscribe> List-Archive: <https://sourceware.org/pipermail/elfutils-devel/> List-Post: <mailto:elfutils-devel@sourceware.org> List-Help: <mailto:elfutils-devel-request@sourceware.org?subject=help> List-Subscribe: <https://sourceware.org/mailman/listinfo/elfutils-devel>, <mailto:elfutils-devel-request@sourceware.org?subject=subscribe> Errors-To: elfutils-devel-bounces+patchwork=sourceware.org@sourceware.org |
Series |
libelf: check decompressed ZSTD size
|
|
Commit Message
Aleksei Vetrov
Nov. 23, 2023, 3:31 p.m. UTC
Decompression functions like __libelf_decompress_zlib check that
decompressed data has the same size as it was declared in the header
(size_out argument). The same check is now added to
__libelf_decompress_zstd to make sure that the whole allocated buffer is
initialized.
* libelf/elf_compress.c (__libelf_decompress_zstd): Use return value
of ZSTD_decompress to check that decompressed data size is the
same as size_out of the buffer that was allocated.
Signed-off-by: Aleksei Vetrov <vvvvvv@google.com>
---
libelf/elf_compress.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
Comments
Hi Aleksei, On Thu, Nov 23, 2023 at 03:31:47PM +0000, Aleksei Vetrov wrote: > Decompression functions like __libelf_decompress_zlib check that > decompressed data has the same size as it was declared in the header > (size_out argument). The same check is now added to > __libelf_decompress_zstd to make sure that the whole allocated buffer is > initialized. > > * libelf/elf_compress.c (__libelf_decompress_zstd): Use return value > of ZSTD_decompress to check that decompressed data size is the > same as size_out of the buffer that was allocated. Thanks, this makes sense. If the decompressed size isn't what was encoded in the Chdr then we could reduce the size of the d_buf/d_size, but that probably is not what the user expects. Flagging it as bad/inconsistent data makes sense. Especially since we do the same for zlib compressed data. Pushed, Mark
diff --git a/libelf/elf_compress.c b/libelf/elf_compress.c index c7283c6a..0ad6a32a 100644 --- a/libelf/elf_compress.c +++ b/libelf/elf_compress.c @@ -422,7 +422,7 @@ __libelf_decompress_zstd (void *buf_in, size_t size_in, size_t size_out) } size_t ret = ZSTD_decompress (buf_out, size_out, buf_in, size_in); - if (ZSTD_isError (ret)) + if (unlikely (ZSTD_isError (ret)) || unlikely (ret != size_out)) { free (buf_out); __libelf_seterrno (ELF_E_DECOMPRESS_ERROR);