Received: by 2002:a05:7412:1e0b:b0:fc:a2b0:25d7 with SMTP id kr11csp1312296rdb; Fri, 16 Feb 2024 11:28:56 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCU6hyRvuHXQ8h+tP1FNXzu9mEH4IfWRE2SV58igQXhAlwhnVnr6H99SnLJBsT0HCznIDqtxyXDmgtt4QTwePCQiegJzugNqIId/1RA2bA== X-Google-Smtp-Source: AGHT+IG1lhbwHHTLHphN9ie4yQ7Qilbz4VBs3Tn8EUHRQl4NCN6PA5OwF0ytu8VWTdCNptZX2Bur X-Received: by 2002:a9d:5914:0:b0:6e4:3e64:b01 with SMTP id t20-20020a9d5914000000b006e43e640b01mr800305oth.5.1708111736498; Fri, 16 Feb 2024 11:28:56 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708111736; cv=pass; d=google.com; s=arc-20160816; b=zkmWT+eH+1c4b/pWusa6/2HuR6mx6LxWSNB2CLZR/iDYzdwyXoEsM6YoIXqvHG/onr xN2qo9uMNW6p/a8i8/LAnl00IciWYVvqIeBGIn9pM3M9cCFwuuiTPGj3RCnfvFNAKizz cmVgv2SVsFohi56/6CctSrBn9r6nASCSomlyJ8BPJSLyqGuKXoKs22DpCIsibDpVpaIs zrgrl7KWbdFAjeJy8rtuzCrUq4DDQg5PBmNWGf+mi9n1mmBkil2hreW7wUjp7nbGcwam LG9uaqfNnD/zoSHTBJjGTW4Ml2YLSfd6C2zODmWTHT8z9s+fEEettgLrQjfBz0PI+4vK +rfg== 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=u8WkqZPPSvCs0Xbxi28cm5IAK+G5lVBNtuRMx7zqp6A=; fh=iIKICQ/yB/Ag151fKjWQ9amCZ4MjQOd0WY7sYcidQC8=; b=uDrkDCBE5oXI6hhHMoZENWxCBN91AhTsozzPFXFXAP6+hmV8G8/T/6nSYJlCOZUQIA BJVFxaAPeVOoVtcM2M5HjbYcWtiY8QRHzjfhVNeIDpT1sI2xNchZ01hnqHb8c6J24cKW bMVQvLh5CCV+JzrUNIoYkgfZ0//UE9DrZansWDxeIAEjb4uKUCbTeozKAM4MCEKjItfj +sIKv3DgjhMxeS6neDeHsoyYa97t5lEiHuXjSvxd4qvjlPH4O7OmHtEJGhfxOP19kII9 QffsSHC4WDahQeMYkHBWSXaSvSpU0C94DmqdbYDjtvjc1nfJC/2SRYfO3obCeLVcKNc5 VYcA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=R5coQsS2; 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-69245-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-69245-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id i13-20020a05620a144d00b0078725cb1f0dsi524654qkl.698.2024.02.16.11.28.56 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Feb 2024 11:28:56 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-69245-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=R5coQsS2; 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-69245-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-69245-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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 407041C21F8C for ; Fri, 16 Feb 2024 19:28:56 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 379E21369B4; Fri, 16 Feb 2024 19:28:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="R5coQsS2" Received: from mail-pl1-f177.google.com (mail-pl1-f177.google.com [209.85.214.177]) (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 8EAFE1350C7 for ; Fri, 16 Feb 2024 19:28:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.177 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708111730; cv=none; b=VHL7r9tKbdQvjbslGTC8j60N/0EQompy1YRKkalikMTRb+nj9Pb69SteruuzP5TFwnf3bwK2jdRvHt5ALa/BH4c8txHmj0uMtS3hWG6D2Q38TmR2uFn8E0mEkCGOB2F7SzdGYSDtBZY4PnU9+nlk/EGGOcaw+BN9pcuq91sUy+k= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708111730; c=relaxed/simple; bh=lTlPLpCMgZP3J5G2JyWCxdrQPIx57yknIxy+xzBAuiQ=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=AWlBK3CfQCpUQVTsFRTHSjRGfeNJec6LxrZWJcLiEjxh9ywsKuhK7cjNeqHY6MV8e8KzAq0B5AgbdNZhxDtJ1qOJ82ejcOlF8nqCxixMVdag1IE/f/iEeGlV/xN2P9/yFKUS8f6S2Dq5N102d4/nOaOR9SA8wOieipcW9QF2dL4= 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=R5coQsS2; arc=none smtp.client-ip=209.85.214.177 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-pl1-f177.google.com with SMTP id d9443c01a7336-1d932f6ccfaso21618005ad.1 for ; Fri, 16 Feb 2024 11:28:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1708111727; x=1708716527; 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=u8WkqZPPSvCs0Xbxi28cm5IAK+G5lVBNtuRMx7zqp6A=; b=R5coQsS2C1Vv8ORE4KkSAKbL7np+3B8cvptkWAn6ATmF49khFocLjmmzWjUCXVQf3G ZdQ6Wtk/WC1PU1DLBzXClJ9LHH2dfjOtssCJVm2vKJRP36783uvFJcvruU7v6J/5mRZK UHRscOq1hh9o2QadEgfeFLQFCJ8F6J3PiLlzI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708111727; x=1708716527; 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=u8WkqZPPSvCs0Xbxi28cm5IAK+G5lVBNtuRMx7zqp6A=; b=XjkwOrUfmSIpWZwHZAxO4HIItZr/NZSZOJHB4AEPYGQc65xSJPosUYugAkpQh+vCwL Mwpq5ZhMqGw6HjZDr0lRV3JAGZ20Yqc1D8zbVfIEpprrYXiDz3g37fnqs/haqDAiAVJl cvibhNEoZeNwXin4yt8vMGAXRiPEqAXYPUFeuxZk38rxDmlVNFQiy5UJ4bE0ytiFwCnX Qu2Y2QMTS+f5FgMKYxxIi9uWcw6llSDSuZ1ad+MW+Db5d3xiYYo6AoYNIe9dNc9ZGqfR W6TRPA6fkGXNw+dUddU6YSLdtdbzSe6IO1zlq8dNV6cixmrSIx6/rES9mwqgaDk8rLYs me2w== X-Forwarded-Encrypted: i=1; AJvYcCViltNNEpAn6H5eNDgGhUeehHWhJwVQRARNxgeoQPuHH578ik3Lz7j1AR3cTbY44CBCarPSIjYD0USs6IeT/j77+VBTXiYAtJ7W/DD9 X-Gm-Message-State: AOJu0Ywuc4hUzMVxrGXdwsqVfDn87Vie2qZ38FclV82BnRqE7t5PpXyo 9PTA+jxu5Umg5iXuaBDc+jd2xKf3vMIDORsv2olsCZ2PDyXbNlAQQ1s1UM2fmSpv2K7jWqXIqT0 = X-Received: by 2002:a17:902:ce90:b0:1db:c1d4:8151 with SMTP id f16-20020a170902ce9000b001dbc1d48151mr348857plg.49.1708111726925; Fri, 16 Feb 2024 11:28:46 -0800 (PST) Received: from www.outflux.net ([198.0.35.241]) by smtp.gmail.com with ESMTPSA id e2-20020a170902d38200b001da0a698095sm205675pld.282.2024.02.16.11.28.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Feb 2024 11:28:46 -0800 (PST) Date: Fri, 16 Feb 2024 11:28:46 -0800 From: Kees Cook To: Christophe Leroy Cc: Luis Chamberlain , linux-modules@vger.kernel.org, linux-kernel@vger.kernel.org, "linux-hardening @ vger . kernel . org" , Marek Szyprowski , Mark Rutland Subject: Re: [PATCH v2] module: Don't ignore errors from set_memory_XX() Message-ID: <202402161128.21EA3F8@keescook> References: <21037bf38438a285f5dff9501668f1675bc45989.1708070781.git.christophe.leroy@csgroup.eu> 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: <21037bf38438a285f5dff9501668f1675bc45989.1708070781.git.christophe.leroy@csgroup.eu> On Fri, Feb 16, 2024 at 09:14:27AM +0100, Christophe Leroy wrote: > set_memory_ro(), set_memory_nx(), set_memory_x() and other helpers > can fail and return an error. In that case the memory might not be > protected as expected and the module loading has to be aborted to > avoid security issues. > > Check return value of all calls to set_memory_XX() and handle > error if any. > > Add a check to not call set_memory_XX() on NULL pointers as some > architectures may not like it allthough numpages is always 0 in that > case. This also avoid a useless call to set_vm_flush_reset_perms(). > > Link: https://github.com/KSPP/linux/issues/7 > Signed-off-by: Christophe Leroy Yay! Glad to see this happening. Universal __must_check for set_memory_*() starts to appear on the horizon. ;) Reviewed-by: Kees Cook -- Kees Cook