Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp1641375pxb; Mon, 22 Feb 2021 07:17:17 -0800 (PST) X-Google-Smtp-Source: ABdhPJwnVydKgXcAJVIaK5um80nBrDIZXM+4MWYEeQ1Lk9SCKhX0qUgjEhDb5P9k/SOm5zJdDckz X-Received: by 2002:aa7:de0f:: with SMTP id h15mr16093399edv.140.1614007037706; Mon, 22 Feb 2021 07:17:17 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1614007037; cv=none; d=google.com; s=arc-20160816; b=xc970ORmhhKghyxFAwyKtqj+ppwmYYb/qY1al6HjDZ7xeKjsyc0rf5CNnsBUiS47uv 8ZUFvKTBKDSllyX9goGNWNmQ08y/xG9L4Kbeo+f9ltMHtlAeRPYg+zZRVgwCWHWUvhRz +O5bLAsyefZObHw6vx6feYlSzWG1gqL+Qxq5ENfQFtXgjYlWZX9J+Z1sA5Qew6UpMun8 rVloWzRuiIFD5Qr414zA3BTat6mKOK8dodMxrrRoiy7HQPD53tAIQ9SLczpgXFEmekOZ LiW2eOBJwi4d7c/guCjmev0zXZRwzo0HnFFPp7G1v1gCcwA393czWFe0gF4wlKyF2UZT Guzg== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=LLkuX0+ITGWZ/iVnAzMULSxwtPPckweuLMISePt9ssw=; b=Rwe6oWPaZKiVgVn45+j67X5t3flL8XA5iioHXJyDdQMD2V4gwuOjEJwuchJeYpOjvg jmIT5GJsoE8cuV6Ny4mEmjqI2L2zOJMqvGv6dEsHXHIIV4JptZQxEq+SoYsTyu5t3FYX hOhKUFhQ4AE6DPGVNLFaFDsm+iWjcSWqjk0RPcxYAQRu+fYvtooKEw5E4CMMRSbbjA46 UKOIz4qWwx0QVLbU1+CcPXlBL6CTxX/GzrtKynXvLkei9q9sahexpfchKrcnFFBVig+c tsQ/tb0zMGBnH41+qosDiwNCiOOCfT3iERdUJUZeETORnZ1KfyQjz/nv/3JNtC1Hqtmg jjkg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=BPykAZVv; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id eb13si13958017edb.8.2021.02.22.07.16.53; Mon, 22 Feb 2021 07:17:17 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=BPykAZVv; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231414AbhBVPPZ (ORCPT + 99 others); Mon, 22 Feb 2021 10:15:25 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40058 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231241AbhBVPNz (ORCPT ); Mon, 22 Feb 2021 10:13:55 -0500 Received: from mail-wm1-x332.google.com (mail-wm1-x332.google.com [IPv6:2a00:1450:4864:20::332]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 20545C0617A7; Mon, 22 Feb 2021 07:12:51 -0800 (PST) Received: by mail-wm1-x332.google.com with SMTP id i9so3926585wml.5; Mon, 22 Feb 2021 07:12:51 -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 :mime-version:content-transfer-encoding; bh=LLkuX0+ITGWZ/iVnAzMULSxwtPPckweuLMISePt9ssw=; b=BPykAZVvUp4icbQV3I8OKq3dgj9xE7I0bXvTLRa+lLFvT2T9S46GpK5rzpalk0vka7 EMAebBc4xNncmRW0iYtFoKILmLT9xpNRKjXNkKgGb+RdrBDYrM86Ih0zaynkmOTCb5LP NaKo4wGex24T0J5JuUZcwofRPEBZMW4HusebFD6CYD7Muei1Q9Ep+FX3tFJoNNyi6fQ4 vE8B0dAximKDBpReNOj1/mEWaFJRZGAdbJ6d3RmzX4lwPElZ4tQbzdIkzl+VgYesDdXm 1qtG97aM1OEtTOrV6g9qGUbFcX4kZio/WjmW8dJAY8W54ikoDB+MgxYkLUCWt2nF9F/v xpkQ== 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:mime-version:content-transfer-encoding; bh=LLkuX0+ITGWZ/iVnAzMULSxwtPPckweuLMISePt9ssw=; b=t8e3DWaynfASCENevG8YlmPo5GrYiVVFXKIj9scJ4wmW7RynSfmcyWx8RNxMa4dY2K F+hYXyZFTgExhFu0DrdQ89vIttPIna6bawPKhnn5GerNQqxhH2927l5X4B4M7eF3L5SF 1CGCeQ66o8XBoCrD5IY5VoIC6qJlxRUzgTUaDbgL+IaFvIDJ56b9mwVGTFVR25HZ3COT r+q0TzDVhq1nDNyuIlJhNb7r7JRoxkY0keZwYoJxae3Fm2pgcEZw9539LtpTwdcrpYKf SVl2hZOJithkUpaUeALs3ibL1OJUQEpjvQ/4oqGlKRtbOvDj5tNoe1r2RU6jX0zYq3YA q/TQ== X-Gm-Message-State: AOAM531b8Eans2ce0nyTMOWOYumrv9SMuw51RGgOL9qcbOSDd43PqSGS UO/6S3ILaVhNsr0onNxUSX9/d8FXEVc5Zc30VGY= X-Received: by 2002:a1c:2094:: with SMTP id g142mr20921780wmg.101.1614006769655; Mon, 22 Feb 2021 07:12:49 -0800 (PST) Received: from debby (176-141-241-253.abo.bbox.fr. [176.141.241.253]) by smtp.gmail.com with ESMTPSA id l15sm26251391wmh.21.2021.02.22.07.12.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Feb 2021 07:12:49 -0800 (PST) From: Romain Perier To: Kees Cook , kernel-hardening@lists.openwall.com, Mimi Zohar , Dmitry Kasatkin Cc: Romain Perier , linux-integrity@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 06/20] ima: Manual replacement of the deprecated strlcpy() with return values Date: Mon, 22 Feb 2021 16:12:17 +0100 Message-Id: <20210222151231.22572-7-romain.perier@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20210222151231.22572-1-romain.perier@gmail.com> References: <20210222151231.22572-1-romain.perier@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The strlcpy() reads the entire source buffer first, it is dangerous if the source buffer lenght is unbounded or possibility non NULL-terminated. It can lead to linear read overflows, crashes, etc... As recommended in the deprecated interfaces [1], it should be replaced by strscpy. This commit replaces all calls to strlcpy that handle the return values by the corresponding strscpy calls with new handling of the return values (as it is quite different between the two functions). [1] https://www.kernel.org/doc/html/latest/process/deprecated.html#strlcpy Signed-off-by: Romain Perier --- security/integrity/ima/ima_policy.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/security/integrity/ima/ima_policy.c b/security/integrity/ima/ima_policy.c index 9b45d064a87d..1a905b8b064f 100644 --- a/security/integrity/ima/ima_policy.c +++ b/security/integrity/ima/ima_policy.c @@ -790,8 +790,14 @@ static int __init ima_init_arch_policy(void) for (rules = arch_rules, i = 0; *rules != NULL; rules++) { char rule[255]; int result; + ssize_t len; - result = strlcpy(rule, *rules, sizeof(rule)); + len = strscpy(rule, *rules, sizeof(rule)); + if (len == -E2BIG) { + pr_warn("Internal copy of architecture policy rule '%s' " + "failed. Skipping.\n", *rules); + continue; + } INIT_LIST_HEAD(&arch_policy_entry[i].list); result = ima_parse_rule(rule, &arch_policy_entry[i]);