From patchwork Tue Oct 31 12:32:06 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ondrej Mosnacek X-Patchwork-Id: 13441496 X-Patchwork-Delegate: paul@paul-moore.com Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7B466C4332F for ; Tue, 31 Oct 2023 12:33:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344268AbjJaMdm (ORCPT ); Tue, 31 Oct 2023 08:33:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37838 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344044AbjJaMdl (ORCPT ); Tue, 31 Oct 2023 08:33:41 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 78FFCDB for ; Tue, 31 Oct 2023 05:32:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1698755540; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=01Cuhkq/fZzHdIhk7dn370LtT6qVzQS52GEFoCa52Y8=; b=EdtapYptE4dF+vxj562P0hSPy2uAL35r53AHMWkD7YCa42vB6SsbZurbPJOaBQ6Urson7A hsD1AuHpQs+wGt29wsc71LxUjbMO1DI0MRrtyhePN/GGE7CBE/8Vq16XWW1g6qQy1mN2gX KM2ADC+jJw5m3EWP2F3vjCdgiaXTCMo= Received: from mail-qk1-f198.google.com (mail-qk1-f198.google.com [209.85.222.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-534-U-TJKo_NP0my1sbQVWSu8A-1; Tue, 31 Oct 2023 08:32:12 -0400 X-MC-Unique: U-TJKo_NP0my1sbQVWSu8A-1 Received: by mail-qk1-f198.google.com with SMTP id af79cd13be357-7789a691086so687849785a.0 for ; Tue, 31 Oct 2023 05:32:12 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698755532; x=1699360332; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=01Cuhkq/fZzHdIhk7dn370LtT6qVzQS52GEFoCa52Y8=; b=I8epz3A3JAsgn2jXOPcdp5th+G0zZSWjC61eISJ3A3+mGzhHbuvbhJiTXI/ocC0yGt inUIcYuJTT3UIxodsqj/0ZqRfaHj4fZMREY11+wcH3n1CVTdt+R6sd+o4sdrgBGOKfnt SWqyBjA78OgZJ3FaEzl33bQhXa7hUZMr/PDnS8WIhOPOdoZwuA/UBJ4nE0mzMrN8ShKO S1WrcghGtXIdz6/CpZVGAS8XvlSrOqhYFotQxWyvHrzoQvITFV3MLtEfhjvoGZ6amdJ4 WEsPjRMDDCzV87bJZudTrFCe1MNd5oetmKl83/MWuwLwyQzV9rh2ESHaq05HPwWllnQ3 cY7Q== X-Gm-Message-State: AOJu0YyOEiJWfXCOdghq6WD5pt9YcMo1QHnseSye0fRSchJc1yxoGtxi gYGlUI+5OxkRqRjrqsJ/8G4VrdleZE0Ke7Oo3kb75nEdQbxaDwpCzbS94y62AIMJnw3srDvJS+q T7U0a5a3ZFxL4joennS4kEtsg+efQShWAkzyk X-Received: by 2002:a05:620a:4109:b0:775:681d:dc06 with SMTP id j9-20020a05620a410900b00775681ddc06mr15146856qko.63.1698755532024; Tue, 31 Oct 2023 05:32:12 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFtP5GHt2Cr+NcxBoAmMp/ehlVMchXJA7rXREzot7xDH4Twt77eyMwn8XXa3E8PspHWfUt1Kg== X-Received: by 2002:a05:620a:4109:b0:775:681d:dc06 with SMTP id j9-20020a05620a410900b00775681ddc06mr15146835qko.63.1698755531737; Tue, 31 Oct 2023 05:32:11 -0700 (PDT) Received: from localhost.localdomain (nat-pool-brq-t.redhat.com. [213.175.37.10]) by smtp.gmail.com with ESMTPSA id g23-20020a05620a13d700b00777063b89casm457697qkl.5.2023.10.31.05.32.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 31 Oct 2023 05:32:11 -0700 (PDT) From: Ondrej Mosnacek To: Paul Moore Cc: linux-security-module@vger.kernel.org, Benjamin Coddington , linux-nfs@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 1/2] lsm: fix default return value for vm_enough_memory Date: Tue, 31 Oct 2023 13:32:06 +0100 Message-ID: <20231031123207.758655-2-omosnace@redhat.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231031123207.758655-1-omosnace@redhat.com> References: <20231031123207.758655-1-omosnace@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Precedence: bulk List-ID: 1 is the return value that implements a "no-op" hook, not 0. Fixes: 98e828a0650f ("security: Refactor declaration of LSM hooks") Signed-off-by: Ondrej Mosnacek --- include/linux/lsm_hook_defs.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/linux/lsm_hook_defs.h b/include/linux/lsm_hook_defs.h index 99b8176c3738d..4dd55fdfec267 100644 --- a/include/linux/lsm_hook_defs.h +++ b/include/linux/lsm_hook_defs.h @@ -48,7 +48,7 @@ LSM_HOOK(int, 0, quota_on, struct dentry *dentry) LSM_HOOK(int, 0, syslog, int type) LSM_HOOK(int, 0, settime, const struct timespec64 *ts, const struct timezone *tz) -LSM_HOOK(int, 0, vm_enough_memory, struct mm_struct *mm, long pages) +LSM_HOOK(int, 1, vm_enough_memory, struct mm_struct *mm, long pages) LSM_HOOK(int, 0, bprm_creds_for_exec, struct linux_binprm *bprm) LSM_HOOK(int, 0, bprm_creds_from_file, struct linux_binprm *bprm, const struct file *file) LSM_HOOK(int, 0, bprm_check_security, struct linux_binprm *bprm) From patchwork Tue Oct 31 12:32:07 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ondrej Mosnacek X-Patchwork-Id: 13441494 X-Patchwork-Delegate: paul@paul-moore.com Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 35BA7C4332F for ; Tue, 31 Oct 2023 12:32:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344271AbjJaMc5 (ORCPT ); Tue, 31 Oct 2023 08:32:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35654 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344246AbjJaMc4 (ORCPT ); Tue, 31 Oct 2023 08:32:56 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7A42B98 for ; Tue, 31 Oct 2023 05:32:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1698755535; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=IwcTumPEA8MXD9aE6NAuiQnpk8SlcZkJMMNjOT52wQs=; b=fssdZvZHBYokIq/zHxOozixsLLJyKetALYZTmiu/97OjX2oOY8MNnLVuH/3jFnVW+zxn52 eu0LZSRQj8HZTmKAcA3n2hu0IRAX72i6OLlA57VcS/yQXpsxe4UdqyhIDZFZfDP98lEwTV QZtDaYHZnkUG02NA7519MgSjhow8/Os= Received: from mail-qk1-f198.google.com (mail-qk1-f198.google.com [209.85.222.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-517-cthUV14aPVCEaXTs4FjvUg-1; Tue, 31 Oct 2023 08:32:14 -0400 X-MC-Unique: cthUV14aPVCEaXTs4FjvUg-1 Received: by mail-qk1-f198.google.com with SMTP id af79cd13be357-7789405320fso708054385a.0 for ; Tue, 31 Oct 2023 05:32:14 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698755533; x=1699360333; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=IwcTumPEA8MXD9aE6NAuiQnpk8SlcZkJMMNjOT52wQs=; b=gLYOQ6xQs0TZYn+sGh8r4Rp/ZGbiZjB4D9WprLxOwS2+xmgn+L/Xr/W4bUF5PEnCfp 7H5xMMlgCq/wyHOp5m97RFvgwxJ7ZEiVKfhrzhLXLJBzFD91iVTYiwS4sUzHVsLu8va6 BArVz9rpJGfCe/tw+NvN650cSbuOMa73g++WVLBnvtMIKtjq+ziXN1xiJrwh3padFdtJ hfzQ/1czzxGpnluGULlNGkCNEEtqVgOhF0LqwOlX6nXL4aaAFWEz9XdDWEB83E6bdZFt GGPtsaSmq1PjKyLmn8KTrtDaXpQUyiIzY7z836oBAzv9dWQDz3+7kGClp4EJRx4HSZ04 O5Pw== X-Gm-Message-State: AOJu0YzsiywCQu90ncwrqMQ3XduDDn6uvhdwMYxRt4/7XTZ15ORnxD0D 8+u4LBx3dlipV+syg3z7ig153kk4OwikW7NMgzP8hhpXCDWyB2bGzcb3D96sd7V8UQbdvoxLbkB Q6NwyVrMEv6Oyfsq+SvzsfNbBpZ/gaTPJIgvM X-Received: by 2002:a05:620a:2408:b0:774:2e8f:2170 with SMTP id d8-20020a05620a240800b007742e8f2170mr15537037qkn.4.1698755533768; Tue, 31 Oct 2023 05:32:13 -0700 (PDT) X-Google-Smtp-Source: AGHT+IF1PibxJcjMn2MZ8vm902icTDEZ+hR9K82a6PAvEbaLbNmN/JzZjcwNxAmmW4i0Zd0iBebAFA== X-Received: by 2002:a05:620a:2408:b0:774:2e8f:2170 with SMTP id d8-20020a05620a240800b007742e8f2170mr15537013qkn.4.1698755533490; Tue, 31 Oct 2023 05:32:13 -0700 (PDT) Received: from localhost.localdomain (nat-pool-brq-t.redhat.com. [213.175.37.10]) by smtp.gmail.com with ESMTPSA id g23-20020a05620a13d700b00777063b89casm457697qkl.5.2023.10.31.05.32.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 31 Oct 2023 05:32:12 -0700 (PDT) From: Ondrej Mosnacek To: Paul Moore Cc: linux-security-module@vger.kernel.org, Benjamin Coddington , linux-nfs@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 2/2] lsm: fix default return value for inode_getsecctx Date: Tue, 31 Oct 2023 13:32:07 +0100 Message-ID: <20231031123207.758655-3-omosnace@redhat.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231031123207.758655-1-omosnace@redhat.com> References: <20231031123207.758655-1-omosnace@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Precedence: bulk List-ID: -EOPNOTSUPP is the return value that implements a "no-op" hook, not 0. Without this fix having only the BPF LSM enabled (with no programs attached) can cause uninitialized variable reads in nfsd4_encode_fattr(), because the BPF hook returns 0 without touching the 'ctxlen' variable and the corresponding 'contextlen' variable in nfsd4_encode_fattr() remains uninitialized, yet being treated as valid based on the 0 return value. Reported-by: Benjamin Coddington Fixes: 98e828a0650f ("security: Refactor declaration of LSM hooks") Signed-off-by: Ondrej Mosnacek --- include/linux/lsm_hook_defs.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/linux/lsm_hook_defs.h b/include/linux/lsm_hook_defs.h index 4dd55fdfec267..ff217a5ce5521 100644 --- a/include/linux/lsm_hook_defs.h +++ b/include/linux/lsm_hook_defs.h @@ -273,7 +273,7 @@ LSM_HOOK(void, LSM_RET_VOID, release_secctx, char *secdata, u32 seclen) LSM_HOOK(void, LSM_RET_VOID, inode_invalidate_secctx, struct inode *inode) LSM_HOOK(int, 0, inode_notifysecctx, struct inode *inode, void *ctx, u32 ctxlen) LSM_HOOK(int, 0, inode_setsecctx, struct dentry *dentry, void *ctx, u32 ctxlen) -LSM_HOOK(int, 0, inode_getsecctx, struct inode *inode, void **ctx, +LSM_HOOK(int, -EOPNOTSUPP, inode_getsecctx, struct inode *inode, void **ctx, u32 *ctxlen) #if defined(CONFIG_SECURITY) && defined(CONFIG_WATCH_QUEUE)