Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp30473978rwd; Thu, 6 Jul 2023 06:31:06 -0700 (PDT) X-Google-Smtp-Source: APBJJlFozH7k5apCrV18K+SuKBM8pP67K9TZbpRColZXv/OqKnQArLgFb0vTy3dkbAw4AYtyTdBG X-Received: by 2002:a05:6870:4194:b0:1b0:73e0:97eb with SMTP id y20-20020a056870419400b001b073e097ebmr2266357oac.30.1688650265972; Thu, 06 Jul 2023 06:31:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688650265; cv=none; d=google.com; s=arc-20160816; b=rqZw59NeWbNDGhJ+e1ZK2FxLCzzDQBcUEXQErRcArWZhEM4XL4Ha2IF4QyCP4CB7+M flEpA51TUbJzi/Xk5EU2Mmj3HA/n08Bw8iE7XJg5DV4Mr8waWOJXeDzk+fTE0MHreOiL SCFBRXogdwiAb1K09z+0Q7Wfkc/TUWH8C+AI+j04Z+CV66HlASHCGW++xCwPlONo/Jz5 tXStf2zR5R8PpU5EuyT3ZZrz8CHokf+qmPcKCMvqlNDUTrxb4Eafd9pVTpihkrKRo+/T g0HeBNnHAtIw/YHfvKwOOJtmg8XBn+ZKB0BLJMQ3ei8oV2W1QBSz496vWl0hvAzT2hkV hq6Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=YMgn8v5HSr1CwulZfQm2e0c4LiCcjYghl7RePYF3Io4=; fh=QKur2PFwoLuCt27JzfZM4LabS9ldoGoSAJNPH9t/KWI=; b=kd/U1ZIxNmOU8fg22DHwkA8gc8uQwBOCs60jsTeu/A/xiE/uqCJ8R/zxhlOLbSERjm XQt3X/cpOyUx3oLWmnoL1vsleB9bvQMyauDtn42zcSMHZVVY20rJGbplLkofp8utadCu 8d4LmirQdMhfzAjHT0ogciuC4iHFAbzPNCFigJ6JnWQKVweSTN9s14POptg1yVwZRtUP v4+5IJqZ4bBfCgwm87pqVNCXuD/8cFieF8PF/gsLopAgQD2+NY5OifHCn/JdZOJPWo/h gMPaMM1PnxShfQgBDITHfqLxYh7sydrpXSMu09lrVAv8Od5BHML/XgaoZZ+J7+DvJChb MVNQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@googlemail.com header.s=20221208 header.b=jpy3SNoT; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=googlemail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ei23-20020a17090ae55700b0025defcc6e75si1432614pjb.172.2023.07.06.06.30.47; Thu, 06 Jul 2023 06:31:05 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@googlemail.com header.s=20221208 header.b=jpy3SNoT; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=googlemail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231600AbjGFNXr (ORCPT + 99 others); Thu, 6 Jul 2023 09:23:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41054 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229919AbjGFNXq (ORCPT ); Thu, 6 Jul 2023 09:23:46 -0400 Received: from mail-ej1-x62b.google.com (mail-ej1-x62b.google.com [IPv6:2a00:1450:4864:20::62b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6995B1994; Thu, 6 Jul 2023 06:23:45 -0700 (PDT) Received: by mail-ej1-x62b.google.com with SMTP id a640c23a62f3a-992acf67388so81793166b.1; Thu, 06 Jul 2023 06:23:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=20221208; t=1688649824; x=1691241824; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=YMgn8v5HSr1CwulZfQm2e0c4LiCcjYghl7RePYF3Io4=; b=jpy3SNoTSnMnS3x/7zAxQzz/XTlzy17ldr228oGAP/Xg3V+9epfdo7Z6fxtc61UDY6 BF9Jic/dXx03T4dhI9Z2/nmLamZVb9XV7stxUkqVGdmcxTEHj8Sc3P7e5J5/ywfubHPJ 53AR6eU2vP0kXzZ2V05E5Cq0hNMEss9qE+Jr4fiU/V8/HU/VFrUn8rQ3sJ5vEST9RwRM hs+LPBn6dznCGQVF78+4O1/mI76LLSqwn0gqCEBZ5VvLLEovATYVnvn9K91/V5ikdy0m PHIewlEU+uEsezVRORrmi1ZkJHUhVPEP501P81U5exIcNEUwvhqahsDqcPuU9grOGAa7 TBww== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688649824; x=1691241824; 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=YMgn8v5HSr1CwulZfQm2e0c4LiCcjYghl7RePYF3Io4=; b=WcfmKpqOA+vYe6vR9SLsfa/qQq4g2irLGPhpJcTUhcyu2pikZqDbzX1rcHg7zzN9ej QubZOEj4VoxVbh7RDnNRwOqBVyO6Nv9Ov65YM3I9ww5UkKQgJmrrPyZSdQfy0a7etkNA i28tNRSR5nv4Ezx8CQ/4QMoAF6MK3uCeHVPEvpFsHMkLuVv4bqL7qI4DEZjCZNBwdqTA +Cljh6m9dMfvxx0YgF8b6UzfcUArnWDWWTjHp6mMW6WlkPgPdjpo9i6r2ZzrjKsNtqwB IVQK/ohiHvIFRo6mLVRHLOaIn0wnxjGrcEm52KdXVkDYnr1ZXV8U+aVdXWyC9J6iiPdz B3CA== X-Gm-Message-State: ABy/qLaeC+dXvmDldtJriJpT1W/fvaa8gdvBKR0YnXAxfWgqaqiupQEs rXnVgDGaXhsRIHpTpTeyZqit/pZ6BjK0oPCB X-Received: by 2002:a17:906:51da:b0:992:4a1b:30e2 with SMTP id v26-20020a17090651da00b009924a1b30e2mr1598976ejk.7.1688649823591; Thu, 06 Jul 2023 06:23:43 -0700 (PDT) Received: from debian_development.DebianHome (dynamic-077-008-088-179.77.8.pool.telefonica.de. [77.8.88.179]) by smtp.gmail.com with ESMTPSA id r2-20020a170906364200b00988dbbd1f7esm808024ejb.213.2023.07.06.06.23.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 06 Jul 2023 06:23:43 -0700 (PDT) From: =?UTF-8?q?Christian=20G=C3=B6ttsche?= To: selinux@vger.kernel.org Cc: Paul Moore , Stephen Smalley , Eric Paris , linux-kernel@vger.kernel.org Subject: [RFC PATCH 01/20] selinux: check for multiplication overflow in put_entry() Date: Thu, 6 Jul 2023 15:23:16 +0200 Message-Id: <20230706132337.15924-1-cgzones@googlemail.com> X-Mailer: git-send-email 2.40.1 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The function is always inlined and most of the time both relevant arguments are compile time constants, allowing compilers to elide the check. Also the function is part of outputting the policy, which is not performance critical. Also convert the type of the third parameter into a size_t, since it should always be a non-negative number of elements. Signed-off-by: Christian Göttsche --- security/selinux/ss/policydb.h | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/security/selinux/ss/policydb.h b/security/selinux/ss/policydb.h index 74b63ed1173f..6b4ad8e91265 100644 --- a/security/selinux/ss/policydb.h +++ b/security/selinux/ss/policydb.h @@ -366,9 +366,12 @@ static inline int next_entry(void *buf, struct policy_file *fp, size_t bytes) return 0; } -static inline int put_entry(const void *buf, size_t bytes, int num, struct policy_file *fp) +static inline int put_entry(const void *buf, size_t bytes, size_t num, struct policy_file *fp) { - size_t len = bytes * num; + size_t len; + + if (unlikely(check_mul_overflow(bytes, num, &len))) + return -EINVAL; if (len > fp->len) return -EINVAL; -- 2.40.1