From patchwork Thu Dec 21 21:54:18 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vasyl Gomonovych X-Patchwork-Id: 10128453 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 15C0B60318 for ; Thu, 21 Dec 2017 21:55:29 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 08AE32465D for ; Thu, 21 Dec 2017 21:55:29 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id F10D729EA2; Thu, 21 Dec 2017 21:55:28 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A06852465D for ; Thu, 21 Dec 2017 21:55:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751057AbdLUVz2 (ORCPT ); Thu, 21 Dec 2017 16:55:28 -0500 Received: from mail-lf0-f67.google.com ([209.85.215.67]:43321 "EHLO mail-lf0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752901AbdLUVz1 (ORCPT ); Thu, 21 Dec 2017 16:55:27 -0500 Received: by mail-lf0-f67.google.com with SMTP id o26so15245097lfc.10; Thu, 21 Dec 2017 13:55:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=VvMEYrz0E+mhg2uqQGf5oySAcRxxm+ZMNzXv0Qw3OBg=; b=KEbuboYfhpC64ZkuC6++rLMMDwv14BfG6fOVVsjlYI25SPg1OD17mtDfZ53sK9Algv Q8rt8kWQ/HztAT0MBnSBzqHqMek+ecRUUPsY8NQs0XuTvcXGjZ5kU38x0WwersSXP3k7 T8iINBDBmA4V8T6ctGY2OL818uugBxyRilc6XSPGhPy/zZN72BP6RnM31VJV9VLbEgNt 0Iifru56P2K5c3i6tDX1X5ibbB5ad4glLwZmvADB7+0DytYVXS16PsLbICXYNTUGf/4Y uENgOSYF12JF+Qe4Ck5s5IlgNX4AlXkA/o4nnkZwJzk4eKOiNk48TCdpaXA6SGmaKuju qfTA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=VvMEYrz0E+mhg2uqQGf5oySAcRxxm+ZMNzXv0Qw3OBg=; b=MSz0blDI7iN1heuvI2Z1ngZdetsXVpyOHUs3RIsenZTJOeNntJcs1JF2MRoc9HppDz ThFvIXj1WE9G37UJz3mCotFvhzKtaPGntIQ0RhT59Rh/3xxgKXnfUD4X975ZRU0yaTdy vEuLFPqKiTWk5t2igCvWEtDrYHrNGD7po0bIRZkAjpT2I8qdB/yVn4FnVt0waCxGtEvT 0fRrZaYWf2yuRQdMR3bfs7QBDv0YOEU6uxyRCaX0G/HoGijtEaufXYXCmsaIELvqqQMQ lPnF03nCZui4ArQy7AS3SkEhAFgJtCEFRCo0plS4v1sNwIUGGGKhr09Yn3caiXQ8eOX/ Ak9g== X-Gm-Message-State: AKGB3mKOPv4hYarxmtLtYU9+bkZF9Oue9G2shxQA40zCN7t+7x0DbJ1C knvlSejY9w6dp4xWMJLouFQ= X-Google-Smtp-Source: ACJfBov1EZDkYf/4kMRIWRV6XI1BolCORYmOOOZCd4aYe/gXt2jLSbog1S/S/jHSBouQJxP7WOAR6g== X-Received: by 10.46.3.10 with SMTP id 10mr7683568ljd.41.1513893325190; Thu, 21 Dec 2017 13:55:25 -0800 (PST) Received: from localhost.localdomain ([195.254.138.66]) by smtp.gmail.com with ESMTPSA id h13sm4534555lfe.5.2017.12.21.13.55.23 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 21 Dec 2017 13:55:24 -0800 (PST) From: Vasyl Gomonovych To: serge@hallyn.com Cc: Vasyl Gomonovych , Mimi Zohar , Dmitry Kasatkin , James Morris , linux-integrity@vger.kernel.org, linux-security-module@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2] ima: Fix warn potential negative subtraction from max Date: Thu, 21 Dec 2017 22:54:18 +0100 Message-Id: <1513893258-28773-1-git-send-email-gomonovych@gmail.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <20171221180001.GC16008@mail.hallyn.com> References: <20171221180001.GC16008@mail.hallyn.com> Sender: linux-integrity-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-integrity@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Found by smatch: security/integrity/ima/ima_queue.c:122 ima_add_digest_entry() warn: potential negative subtraction from max '(~0)- size' Signed-off-by: Vasyl Gomonovych --- This minor change remove smatch warning but I don't think that before change it was vulnerable, motivation for this patch was smatch report. Changelog: - v2: change get_binary_runtime_size return type security/integrity/ima/ima_queue.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/security/integrity/ima/ima_queue.c b/security/integrity/ima/ima_queue.c index a02a86d51102..3d5f981b8453 100644 --- a/security/integrity/ima/ima_queue.c +++ b/security/integrity/ima/ima_queue.c @@ -74,9 +74,9 @@ static struct ima_queue_entry *ima_lookup_digest_entry(u8 *digest_value, * binary_runtime_measurement list entry, which contains a * couple of variable length fields (e.g template name and data). */ -static int get_binary_runtime_size(struct ima_template_entry *entry) +static unsigned int get_binary_runtime_size(struct ima_template_entry *entry) { - int size = 0; + unsigned int size = 0; size += sizeof(u32); /* pcr */ size += sizeof(entry->digest); @@ -116,7 +116,7 @@ static int ima_add_digest_entry(struct ima_template_entry *entry, } if (binary_runtime_size != ULONG_MAX) { - int size; + unsigned int size; size = get_binary_runtime_size(entry); binary_runtime_size = (binary_runtime_size < ULONG_MAX - size) ?