From mboxrd@z Thu Jan 1 00:00:00 1970 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 8BE27C4332F for ; Tue, 31 Oct 2023 17:06:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234895AbjJaRGE (ORCPT ); Tue, 31 Oct 2023 13:06:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33914 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235480AbjJaRFs (ORCPT ); Tue, 31 Oct 2023 13:05:48 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 48A99199D for ; Tue, 31 Oct 2023 10:03:05 -0700 (PDT) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3FCE6C433C7; Tue, 31 Oct 2023 17:03:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1698771785; bh=uLaa1h3qaVwHW47fye1V818NdRA7WeZIN/Z5YQddxD0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=PLRwd0fapItSSj4oZcaSjA18zWEo6vqxguCLiunJ02lDDHxq8fHav6nxPeDohD7M4 W2EhotulowoQ1MVHxU54pQjwdofdnftS2PA0W9tfQegQClpxaRbCx8/dgndaYZWSAy dEcVyuegl078cgWfbdKxTX5Dk94G9JWmd/dfsY4Q= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Sebastian Ott , Kees Cook , "Liam R. Howlett" , Yu Zhao , Andrew Morton Subject: [PATCH 6.1 20/86] mm: fix vm_brk_flags() to not bail out while holding lock Date: Tue, 31 Oct 2023 18:00:45 +0100 Message-ID: <20231031165919.240148290@linuxfoundation.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231031165918.608547597@linuxfoundation.org> References: <20231031165918.608547597@linuxfoundation.org> User-Agent: quilt/0.67 X-stable: review X-Patchwork-Hint: ignore MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org 6.1-stable review patch. If anyone has any objections, please let me know. ------------------ From: Sebastian Ott commit e0f81ab1e4f42ffece6440dc78f583eb352b9a71 upstream. Calling vm_brk_flags() with flags set other than VM_EXEC will exit the function without releasing the mmap_write_lock. Just do the sanity check before the lock is acquired. This doesn't fix an actual issue since no caller sets a flag other than VM_EXEC. Link: https://lkml.kernel.org/r/20230929171937.work.697-kees@kernel.org Fixes: 2e7ce7d354f2 ("mm/mmap: change do_brk_flags() to expand existing VMA and add do_brk_munmap()") Signed-off-by: Sebastian Ott Signed-off-by: Kees Cook Reviewed-by: Liam R. Howlett Cc: Yu Zhao Signed-off-by: Andrew Morton Signed-off-by: Greg Kroah-Hartman --- mm/mmap.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) --- a/mm/mmap.c +++ b/mm/mmap.c @@ -3147,13 +3147,13 @@ int vm_brk_flags(unsigned long addr, uns if (!len) return 0; - if (mmap_write_lock_killable(mm)) - return -EINTR; - /* Until we need other flags, refuse anything except VM_EXEC. */ if ((flags & (~VM_EXEC)) != 0) return -EINVAL; + if (mmap_write_lock_killable(mm)) + return -EINTR; + ret = check_brk_limits(addr, len); if (ret) goto limits_failed;