Received: by 2002:a05:7412:1e0b:b0:fc:a2b0:25d7 with SMTP id kr11csp161547rdb; Wed, 14 Feb 2024 16:45:55 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCW7YjF5HMdWLksxIWOcgX4pG0CqNIHwSmgByrxLOt+iQC5Mb8jaDEEgsMuuiHooWfyTiwT0OJfpVgbAkWet2prF88WvjMX9QL0CfWjgJg== X-Google-Smtp-Source: AGHT+IECHrPj4xlhygai/RHO2MUhia4qqf2ROC1qwYRe4uINmp0aft+MowXtAE/0XH1IPbAUoPkM X-Received: by 2002:a05:6402:12d0:b0:55f:ef66:4739 with SMTP id k16-20020a05640212d000b0055fef664739mr234751edx.2.1707957955273; Wed, 14 Feb 2024 16:45:55 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707957955; cv=pass; d=google.com; s=arc-20160816; b=jnG5gtGHNNhqw3td/K5+5cToPlA1DFMhRJmdxdNVe8oJnJQP3PPkEEvMqs5YeIvTMW jVdJXWhMn9gv0t7zGwVzRHsWgftlnHwLdsCABgPEgi5CE6ZJe3qHQZ3pakbpYt1kr/KZ 0uV3R1H0mm8xqxajdrlTZIeaBpFUHvFsZgZx2zuGRyQUgKBnJyFM8IUtgS+ZlYVOOuVc 0WpS0v0uGwtIBTzFpiCGd/9maa2eM6YSz3Mh4b0DaM+y1QBrJy+XawHEkpciReYG4Qbq CnHv6Y9mE+DANwom8xqrJ5q9QWOfVCr+IDPhdpoS4dI1b21IVxIk0Lguoi4KrVSg/QZi EXOA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date:dkim-signature; bh=X0AvVNTj/tsYhJ9uNlkS0NKEX6Ozv7KgymDA8FjoHGs=; fh=FEM0Fb09pYugDG4AVItN19vjnZRScoC53oKnzsJnask=; b=mjZiksu3rbGySbhFuunUyX3HXyRtGqQ3lx2OCMd93Lt6rHKMKaJVfbT+Xs32yLTUx7 EeyXX2pduo6aT8SKzTHiAFUJ2AI1Tp8NxxuK2ZdPKVIliVwjJmHxpFiCOcb9qMeXGMIc 8ZUm7gf4h4DD1Cp27y1Qix8TfDgtnxOYX6OvZ2TPbNukLF7xMLmwVn/NAtpzrfXNHJmb 8KByo3UkKftBgnsQtBcyONkqZy+fFeQbNhlv8z+JvlIlVssyghLFNXJvmQRloV1j8GHs Ry+2oX1W2reLii+kL6QR5OUdOUYRyHx166QPTODV2b2sUxkBFYoEyUd3w+aRa7QNgawD o7Ug==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=Cf2UWxre; arc=pass (i=1 spf=pass spfdomain=chromium.org dkim=pass dkdomain=chromium.org dmarc=pass fromdomain=chromium.org); spf=pass (google.com: domain of linux-kernel+bounces-66193-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-66193-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id ba7-20020a0564021ac700b0055845379c80si85995edb.115.2024.02.14.16.45.55 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Feb 2024 16:45:55 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-66193-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=Cf2UWxre; arc=pass (i=1 spf=pass spfdomain=chromium.org dkim=pass dkdomain=chromium.org dmarc=pass fromdomain=chromium.org); spf=pass (google.com: domain of linux-kernel+bounces-66193-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-66193-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 0DB5C1F29E16 for ; Thu, 15 Feb 2024 00:45:55 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A0F61623; Thu, 15 Feb 2024 00:45:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="Cf2UWxre" Received: from mail-io1-f51.google.com (mail-io1-f51.google.com [209.85.166.51]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 63478639 for ; Thu, 15 Feb 2024 00:45:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.166.51 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707957945; cv=none; b=PF9d2reZpbzEYX3kyd3fnIqQySe2dK0V42E5Ey4gBy0bPZheytwr115KHHr+bhlqfNMtuduvjUSrKB1m53+62e117dItEOAjZCp+oapTu7lAMltmYNce8EuYj9k7Jdxz4+EJnjeIXv4kdiAVwj8u2WSr5ZS+cODDIhZ0YAHZfog= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707957945; c=relaxed/simple; bh=57EG/0ZwmKtwXNJ0IzAUfLW8cf7jcqGxUoA0gdV96WM=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=iDBQBQQcI6MNlRKvKD2aDn4/AeqZTE8pLddTIwpGJeGroa3OfRB4L+mHd9QlzBj37QLtR84uJXGy3365OtsEXWfePLEuZ+icKKDX5HfSqJJ2AheuCaSWS0ye+CJjP8a2Iz4uHiRHMRYZ45iQv1d8H1iaFtbE8w9LU6gkxAddOKI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org; spf=pass smtp.mailfrom=chromium.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b=Cf2UWxre; arc=none smtp.client-ip=209.85.166.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=chromium.org Received: by mail-io1-f51.google.com with SMTP id ca18e2360f4ac-7c48fc56752so12334539f.3 for ; Wed, 14 Feb 2024 16:45:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1707957943; x=1708562743; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=X0AvVNTj/tsYhJ9uNlkS0NKEX6Ozv7KgymDA8FjoHGs=; b=Cf2UWxrenRDfBmtCzOFoIyBD/dbfvsZTZV37AqgonJ++TKn10wV0wWX2y7OS3UWw31 tjdYnic7uth4zgE6+fLjrxec71HnDN3vhXOcb2ndsnCx8Ps+ThPwC1Uk99baMnGUGhv8 xSS/nMR35+AgBlH3sZG9s6Z9PSSG8IIgpIHwY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707957943; x=1708562743; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=X0AvVNTj/tsYhJ9uNlkS0NKEX6Ozv7KgymDA8FjoHGs=; b=awPNQ8+XH31Y+4NpVTF9pbQAMh4jGoZfoBTjHqZBomma/GAssjTzJ9xlaquitYSTii bO4AOAx/5NE+Rma0Cm/LPdo8Y2FMXvr9Hb0IoXDI7tFaH/WzjUrGK2zlL1Br/LWktoGW j+KhYhRk8YFjy/POFD/VP+8M2xGSYiS9yQaVQjSp6pJ5t4KUeJtx6MKS0cxh6McCVo+V 2uXafAtglXkEx1aL3GvUinRyYxz1MgvEdKiDpZclmx7YP5O6KdC+JoEDswbFyydEfpNd pYgUuOZSLlsIyQtQeM9zTM9qVWVs95MG5vvJ/0FSQVvAywdFg1r0uM+dsCWdbBAgnawe 860A== X-Forwarded-Encrypted: i=1; AJvYcCVxiPHiA38X9r+eaznl/97Gk270MV8mS85ZK7ylPFjPIQ+LAJCKozY1PRupv4UXd5j2Ftt6RISPyEJrwqdFUf39i4742ix8H/NMF8bD X-Gm-Message-State: AOJu0YwOTUVkvYXX9liMlWL53yfE53RPfxI+8zrlVnJmg4HRUw8Zd+s3 tls8brFVa/LTCjVW4oyDACIDCj+HL4TnaO7UCw4Thiq3D5Q1Kj5ghchkq4YJng== X-Received: by 2002:a92:a30e:0:b0:364:21b0:6050 with SMTP id a14-20020a92a30e000000b0036421b06050mr121980ili.6.1707957943570; Wed, 14 Feb 2024 16:45:43 -0800 (PST) Received: from www.outflux.net ([198.0.35.241]) by smtp.gmail.com with ESMTPSA id s64-20020a635e43000000b005b7dd356f75sm50540pgb.32.2024.02.14.16.45.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Feb 2024 16:45:43 -0800 (PST) Date: Wed, 14 Feb 2024 16:45:42 -0800 From: Kees Cook To: Casey Schaufler Cc: Jann Horn , Paul Moore , James Morris , "Serge E. Hallyn" , John Johansen , linux-security-module@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] security: fix integer overflow in lsm_set_self_attr() syscall Message-ID: <202402141644.808307E71@keescook> References: <20240214160538.1086089-1-jannh@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: On Wed, Feb 14, 2024 at 08:53:52AM -0800, Casey Schaufler wrote: > On 2/14/2024 8:05 AM, Jann Horn wrote: > > security_setselfattr() has an integer overflow bug that leads to > > out-of-bounds access when userspace provides bogus input: > > `lctx->ctx_len + sizeof(*lctx)` is checked against `lctx->len` (and, > > redundantly, also against `size`), but there are no checks on > > `lctx->ctx_len`. > > Therefore, userspace can provide an `lsm_ctx` with `->ctx_len` set to a > > value between `-sizeof(struct lsm_ctx)` and -1, and this bogus `->ctx_len` > > will then be passed to an LSM module as a buffer length, causing LSM > > modules to perform out-of-bounds accesses. > > > > The following reproducer will demonstrate this under ASAN (if AppArmor is > > loaded as an LSM): > > ``` > > #define _GNU_SOURCE > > #include > > #include > > #include > > #include > > > > struct lsm_ctx { > > uint64_t id; > > uint64_t flags; > > uint64_t len; > > uint64_t ctx_len; Do we want to take the opportunity to reduce this to u32 for len and u32 for ctx_len? All FS operations are limited to INT_MAX anyway... -Kees -- Kees Cook