From patchwork Wed May 6 15:21:05 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kees Cook X-Patchwork-Id: 1237014 Return-Path: Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7972DC28CBC for ; Wed, 6 May 2020 15:21:44 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5312F2080D for ; Wed, 6 May 2020 15:21:44 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="KwX6/DXe" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729393AbgEFPVn (ORCPT ); Wed, 6 May 2020 11:21:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58210 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728821AbgEFPVn (ORCPT ); Wed, 6 May 2020 11:21:43 -0400 Received: from mail-pj1-x1044.google.com (mail-pj1-x1044.google.com [IPv6:2607:f8b0:4864:20::1044]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E492AC061A0F for ; Wed, 6 May 2020 08:21:42 -0700 (PDT) Received: by mail-pj1-x1044.google.com with SMTP id y6so1061254pjc.4 for ; Wed, 06 May 2020 08:21:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=0GrsnLomqX5Yv3Tom3gIH7C/pCQ9LgRpoJPzGqJICzI=; b=KwX6/DXeNIsWsWlTUx2Lg/+bGBqtRwjeQ/X4DL9YgbOhA9d/lBCEIBp3b/fQ0YELmd mpAXQ5mJx36IzvHTcFqzSez/beBvtlCZ/ax0p/OKpzb4sYSZw6NEdMJcdB1uR5fwMtGX rlKVbttCR4kfIy8VdJPR8LCi8kESkUr09VpFw= 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=0GrsnLomqX5Yv3Tom3gIH7C/pCQ9LgRpoJPzGqJICzI=; b=hj2yk4iSPqQJ6ddhR3+gtW1zHQXXgyANrKKyotJ1lB32wWA7qi3k5ItPreAlJePPHQ 6zlhR0f8vQ5hI9Sjo1bcnHIl4AabulkJj08vtTQGKli04QlHNQ96o9yNutzMW1leP3uP ZxKYPLYE1jyCSCcw+KkANCfF7lDpDVTzOKU1wu15l/yClfHTZ8HOZpDgHmlsnPn2zaeu H8pMpwn42j34gRicDbZpWi5p6R7aMCNY/TvZt+We4tSq6lVq23tC5OAR+Sdr9v7cX5dh vlsDzixIk1dxWW8SJZPiCgMcj83R788ux+tbwJJtGwYsPu4AgF7Ybke3dTevyukFrsz6 +qrQ== X-Gm-Message-State: AGi0PuZKwXasLQ2ejgfFCltzQOwSUvuXlz9r4gr8DBbCsZu+Ok7dxTT7 rLk+6IsHeUIaxBi6rErycdU0UzUNn8c= X-Google-Smtp-Source: APiQypL1hTpo9FfJpbePD6l9WWohDd139O1SoPM9Xu90TAINWMR+B4rfGx5aoPGQ2ExTdUcYl6HEIQ== X-Received: by 2002:a17:90a:1941:: with SMTP id 1mr9515679pjh.65.1588778502424; Wed, 06 May 2020 08:21:42 -0700 (PDT) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id a22sm2085212pfg.169.2020.05.06.08.21.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 May 2020 08:21:41 -0700 (PDT) From: Kees Cook To: linux-kernel@vger.kernel.org Cc: Kees Cook , Anton Vorontsov , Colin Cross , Tony Luck , Luis Henriques Subject: [PATCH 01/10] pstore: Drop useless try_module_get() for backend Date: Wed, 6 May 2020 08:21:05 -0700 Message-Id: <20200506152114.50375-2-keescook@chromium.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200506152114.50375-1-keescook@chromium.org> References: <20200506152114.50375-1-keescook@chromium.org> MIME-Version: 1.0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org There is no reason to be doing a module get/put in pstore_register(), since the module calling pstore_register() cannot be unloaded since it hasn't finished its initialization. Remove it so there is no confusion about how registration ordering works. Signed-off-by: Kees Cook --- fs/pstore/platform.c | 8 -------- 1 file changed, 8 deletions(-) diff --git a/fs/pstore/platform.c b/fs/pstore/platform.c index 408277ee3cdb..44f8b9742263 100644 --- a/fs/pstore/platform.c +++ b/fs/pstore/platform.c @@ -555,8 +555,6 @@ static int pstore_write_user_compat(struct pstore_record *record, */ int pstore_register(struct pstore_info *psi) { - struct module *owner = psi->owner; - if (backend && strcmp(backend, psi->name)) { pr_warn("ignoring unexpected backend '%s'\n", psi->name); return -EPERM; @@ -591,10 +589,6 @@ int pstore_register(struct pstore_info *psi) sema_init(&psinfo->buf_lock, 1); spin_unlock(&pstore_lock); - if (owner && !try_module_get(owner)) { - psinfo = NULL; - return -EINVAL; - } if (psi->flags & PSTORE_FLAGS_DMESG) allocate_buf_for_compression(); @@ -626,8 +620,6 @@ int pstore_register(struct pstore_info *psi) pr_info("Registered %s as persistent store backend\n", psi->name); - module_put(owner); - return 0; } EXPORT_SYMBOL_GPL(pstore_register); From patchwork Wed May 6 15:21:06 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kees Cook X-Patchwork-Id: 1237020 Return-Path: Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6AEDFC47256 for ; Wed, 6 May 2020 15:22:09 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4BA3420836 for ; Wed, 6 May 2020 15:22:09 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="U9O3LFB1" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729451AbgEFPVt (ORCPT ); Wed, 6 May 2020 11:21:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58228 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729415AbgEFPVp (ORCPT ); Wed, 6 May 2020 11:21:45 -0400 Received: from mail-pg1-x542.google.com (mail-pg1-x542.google.com [IPv6:2607:f8b0:4864:20::542]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BE6D1C061A41 for ; Wed, 6 May 2020 08:21:45 -0700 (PDT) Received: by mail-pg1-x542.google.com with SMTP id t11so1242662pgg.2 for ; Wed, 06 May 2020 08:21:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=abGIv/DdrNJt2Rz7dowQp90zZu4jBR2B6nuWuRnKkME=; b=U9O3LFB1qlKclxe075qGu5xo3xrMDDz7IOdPPcNMZfhaK6oU8/KaCqfVrFbBojb+kF RlstceOC3w4CsecV9rpMFOOR6f6gbx/qyvrTcLsqwy08jxuVW5VfpTDh4ZGVdF70hRDK zrri0EQ9i7U7MezqI+VW/QkhRMsJTYHgj0wIs= 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=abGIv/DdrNJt2Rz7dowQp90zZu4jBR2B6nuWuRnKkME=; b=SX27mw8oE9NhFm0dtk7PHHBXRSnA8QlKDGtcLu2ftCHvPC7zV+qO+BAeWIHw9+bz/I fr/RVKIfnoOHmqxXANK1D3zNsbLpW+Q94XjvE66Wx6STMi1BK96X5sr5qVtojCb9fAAP F33dNGdicAGwWLruDJM6zdlM6Xfnim4WRWGXnFX6mSEc8hBtCU7Vv/IePaF3GYWADBoT oLb/U2Oq9j0aLQGyYDPOxJYTICZ7hez13uCO1PC0NGiDip3qPbQqElBlrrOk57Gkb88a dEl1ixhSonjrb2+ZL/ydWdnjGdGSZrz+4rTjw+OKi++0etDywKodxQijeFbpbwlgtUc7 cw2A== X-Gm-Message-State: AGi0PuZ3Sf2pSIbDEwxkaoOSEn3TlcGPeMpU42J+kI/pJKCXxF0Z+qwX CUzFi3YSx8cTGtPeybAkLmfSqA== X-Google-Smtp-Source: APiQypKRaz6yrGzT3/NYxjULwoEsys/LiTxAitWFf6a1UZRTEc+kLFR9zz4OeLSceQZ40Pvg5yMccg== X-Received: by 2002:aa7:808e:: with SMTP id v14mr8922680pff.168.1588778505369; Wed, 06 May 2020 08:21:45 -0700 (PDT) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id i72sm2287178pfe.104.2020.05.06.08.21.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 May 2020 08:21:41 -0700 (PDT) From: Kees Cook To: linux-kernel@vger.kernel.org Cc: Kees Cook , Anton Vorontsov , Colin Cross , Tony Luck , Luis Henriques Subject: [PATCH 02/10] pstore: Rename "pstore_lock" to "psinfo_lock" Date: Wed, 6 May 2020 08:21:06 -0700 Message-Id: <20200506152114.50375-3-keescook@chromium.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200506152114.50375-1-keescook@chromium.org> References: <20200506152114.50375-1-keescook@chromium.org> MIME-Version: 1.0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The name "pstore_lock" sounds very global, but it is only supposed to be used for managing changes to "psinfo", so rename it accordingly. Signed-off-by: Kees Cook --- fs/pstore/platform.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/fs/pstore/platform.c b/fs/pstore/platform.c index 44f8b9742263..347b6c07f4cf 100644 --- a/fs/pstore/platform.c +++ b/fs/pstore/platform.c @@ -69,10 +69,10 @@ static void pstore_dowork(struct work_struct *); static DECLARE_WORK(pstore_work, pstore_dowork); /* - * pstore_lock just protects "psinfo" during + * psinfo_lock just protects "psinfo" during * calls to pstore_register() */ -static DEFINE_SPINLOCK(pstore_lock); +static DEFINE_SPINLOCK(psinfo_lock); struct pstore_info *psinfo; static char *backend; @@ -574,11 +574,11 @@ int pstore_register(struct pstore_info *psi) return -EINVAL; } - spin_lock(&pstore_lock); + spin_lock(&psinfo_lock); if (psinfo) { pr_warn("backend '%s' already loaded: ignoring '%s'\n", psinfo->name, psi->name); - spin_unlock(&pstore_lock); + spin_unlock(&psinfo_lock); return -EBUSY; } @@ -587,7 +587,7 @@ int pstore_register(struct pstore_info *psi) psinfo = psi; mutex_init(&psinfo->read_mutex); sema_init(&psinfo->buf_lock, 1); - spin_unlock(&pstore_lock); + spin_unlock(&psinfo_lock); if (psi->flags & PSTORE_FLAGS_DMESG) From patchwork Wed May 6 15:21:07 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kees Cook X-Patchwork-Id: 1237016 Return-Path: Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 42DC6C47256 for ; Wed, 6 May 2020 15:21:48 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 219622080D for ; Wed, 6 May 2020 15:21:48 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="b5RMo4Yv" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729428AbgEFPVr (ORCPT ); Wed, 6 May 2020 11:21:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58218 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729403AbgEFPVp (ORCPT ); Wed, 6 May 2020 11:21:45 -0400 Received: from mail-pf1-x441.google.com (mail-pf1-x441.google.com [IPv6:2607:f8b0:4864:20::441]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4B7D5C061A0F for ; Wed, 6 May 2020 08:21:44 -0700 (PDT) Received: by mail-pf1-x441.google.com with SMTP id x77so1154238pfc.0 for ; Wed, 06 May 2020 08:21:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=5aPKY2j9qr0251TLSYO4+fUSg6ZX/RxgODVRo6vIvv0=; b=b5RMo4YvA42TztESKEzSQWr+T9IS3t2tUyslwMCatcIhmfHjeSQLqgglaX2b/JxU+y 0ASyVmM14mcMQQvGdnu1TtdNq++e0uVj4ZNFRLq7PloqDBTEu6jdvKnJLAJc3+PWXUGj O0CHstni5hjbwhMG143Ie23RqLbObXvd+tyts= 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=5aPKY2j9qr0251TLSYO4+fUSg6ZX/RxgODVRo6vIvv0=; b=ozJbUN93xyILW6fmvCLrwavF+Zk6KQGOBr8OkkDwPiuZ9mgxEHSl8Ov/GCptQSo91R uY/Vp2i0+9RXe60GmjhU66dcjoJRdMCgmU0nyhYxYcAZKU+GSFRxP+wuC2jX4qHUmPSG CE4w4siR1BS2ey8mV/clWZpIOaMtIJAe2/l7pqTKP6pfYYXjKiyl+fi7X/llRiOJ72TX gP0G4HmvN54pRSr3tAVS7tVIVK0KUkpU7CsXKfk0jYxIQwztS88c9NxDqwnc/DazSJq0 1JjmHJV86U4I5L3hdbpAhJxkNFQxgaIztqNNTj+a3DXu9zOzlru9dlxM8omcEVmvGyu8 M/iQ== X-Gm-Message-State: AGi0PuaKP4SStwXQ4qyd8XHbZoYWU/oQFJunbZnE5WaC42mvFhL3WJjc TqHeUzcEveTWwPd+VSyw+I9vGw== X-Google-Smtp-Source: APiQypJcdjoglFUBiRCCbRmw7a3B+hdMTzdBapv4zL2vAEcPVK7vXfjZkibGoBYBjdxm08KWkg89/Q== X-Received: by 2002:a63:dc41:: with SMTP id f1mr7683054pgj.348.1588778503907; Wed, 06 May 2020 08:21:43 -0700 (PDT) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id 1sm2121527pff.180.2020.05.06.08.21.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 May 2020 08:21:41 -0700 (PDT) From: Kees Cook To: linux-kernel@vger.kernel.org Cc: Kees Cook , Anton Vorontsov , Colin Cross , Tony Luck , Luis Henriques Subject: [PATCH 03/10] pstore: Convert "psinfo" locking to mutex Date: Wed, 6 May 2020 08:21:07 -0700 Message-Id: <20200506152114.50375-4-keescook@chromium.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200506152114.50375-1-keescook@chromium.org> References: <20200506152114.50375-1-keescook@chromium.org> MIME-Version: 1.0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Currently pstore can only have a single backend attached at a time, and it tracks the active backend via "psinfo", under a lock. The locking for this does not need to be a spinlock, and in order to avoid may_sleep() issues during future changes to pstore_unregister(), switch to a mutex instead. Signed-off-by: Kees Cook --- fs/pstore/platform.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/fs/pstore/platform.c b/fs/pstore/platform.c index 347b6c07f4cf..d0ce22237589 100644 --- a/fs/pstore/platform.c +++ b/fs/pstore/platform.c @@ -72,7 +72,7 @@ static DECLARE_WORK(pstore_work, pstore_dowork); * psinfo_lock just protects "psinfo" during * calls to pstore_register() */ -static DEFINE_SPINLOCK(psinfo_lock); +static DEFINE_MUTEX(psinfo_lock); struct pstore_info *psinfo; static char *backend; @@ -574,11 +574,11 @@ int pstore_register(struct pstore_info *psi) return -EINVAL; } - spin_lock(&psinfo_lock); + mutex_lock(&psinfo_lock); if (psinfo) { pr_warn("backend '%s' already loaded: ignoring '%s'\n", psinfo->name, psi->name); - spin_unlock(&psinfo_lock); + mutex_unlock(&psinfo_lock); return -EBUSY; } @@ -587,7 +587,7 @@ int pstore_register(struct pstore_info *psi) psinfo = psi; mutex_init(&psinfo->read_mutex); sema_init(&psinfo->buf_lock, 1); - spin_unlock(&psinfo_lock); + mutex_unlock(&psinfo_lock); if (psi->flags & PSTORE_FLAGS_DMESG) From patchwork Wed May 6 15:21:08 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kees Cook X-Patchwork-Id: 1237024 Return-Path: Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 11EB1C28CBC for ; Wed, 6 May 2020 15:22:28 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id DFBD72080D for ; Wed, 6 May 2020 15:22:27 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="YAI1tjUp" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729567AbgEFPW0 (ORCPT ); Wed, 6 May 2020 11:22:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58220 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729408AbgEFPVp (ORCPT ); Wed, 6 May 2020 11:21:45 -0400 Received: from mail-pj1-x1041.google.com (mail-pj1-x1041.google.com [IPv6:2607:f8b0:4864:20::1041]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 39D65C061A10 for ; Wed, 6 May 2020 08:21:45 -0700 (PDT) Received: by mail-pj1-x1041.google.com with SMTP id y6so1061301pjc.4 for ; Wed, 06 May 2020 08:21:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=qWlHBN/3hvShJu+ITQ2VKsWR3g9HqwgdpXyZ5LX21CA=; b=YAI1tjUpn5zlOwDJnOxslc63NeKw2d0jLqjUJCgbRGMZA943VBl6kX3k03mQxcjLGv 22f4mSlg/0BhX87quVIuQPUAv18gpArdRPDfpa/FpFcPw5PrFmHA0eEAKJH4ccKb581/ M24qxeyX0yfrodUDuJBMqJqCofeYKccEC4yts= 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=qWlHBN/3hvShJu+ITQ2VKsWR3g9HqwgdpXyZ5LX21CA=; b=n7O5OKm/sP17IGCOxnW/AMpNqMc58jB7+yMkO/0NUM7W7hYXw7aWN7jtNGCSpD1UtY 4w1K+gcCtMa9uK9cXTUJVKWvuIbiS5xve8o1fsE36u+tgJV3SC+3jDkYw8fL+K8Zhdlz adO9EhxXCGp2rpZdfnKhd5QjQkUTvQnMgSAHh/t25fp2A9ur1G3Ve+J3vNDz695sp1Z4 SKzmk9IP/paF6y8upKmDfJIthKFIocTh+5vG+8Ni2QlyBrGbCpZ07qntzVX0DsIps6zZ el2QnyA2TAryRIOfB0dQxD9mvvUncaD0rBYYZfnqQZeCsjZxjlFo5JSZNMWt6EViSTug FonQ== X-Gm-Message-State: AGi0Pua0IiMTcDFRuclzlKmwirKq7D9zyrd5QKJdsDJo882mjKEvH/yx J+xKHQuDvJqH3Byung635VOfKg== X-Google-Smtp-Source: APiQypJf9kdgVvoj0G+zgWGJk7pqjABqsOyRmjsvqCmtvNdvOOBYHPzccyhJuHcyfrjpNp0gSNS4oA== X-Received: by 2002:a17:902:b187:: with SMTP id s7mr9027685plr.0.1588778504733; Wed, 06 May 2020 08:21:44 -0700 (PDT) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id l1sm5048438pjr.17.2020.05.06.08.21.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 May 2020 08:21:41 -0700 (PDT) From: Kees Cook To: linux-kernel@vger.kernel.org Cc: Kees Cook , Anton Vorontsov , Colin Cross , Tony Luck , Luis Henriques Subject: [PATCH 04/10] pstore: Rename "allpstore" to "records_list" Date: Wed, 6 May 2020 08:21:08 -0700 Message-Id: <20200506152114.50375-5-keescook@chromium.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200506152114.50375-1-keescook@chromium.org> References: <20200506152114.50375-1-keescook@chromium.org> MIME-Version: 1.0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The name "allpstore" doesn't carry much meaning, so rename it to what it actually is: the list of all records present in the filesystem. The lock is also renamed accordingly. Signed-off-by: Kees Cook --- fs/pstore/inode.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/fs/pstore/inode.c b/fs/pstore/inode.c index d99b5d39aa90..5cc09cb315f9 100644 --- a/fs/pstore/inode.c +++ b/fs/pstore/inode.c @@ -29,8 +29,8 @@ #define PSTORE_NAMELEN 64 -static DEFINE_SPINLOCK(allpstore_lock); -static LIST_HEAD(allpstore); +static DEFINE_SPINLOCK(records_list_lock); +static LIST_HEAD(records_list); struct pstore_private { struct list_head list; @@ -196,9 +196,9 @@ static void pstore_evict_inode(struct inode *inode) clear_inode(inode); if (p) { - spin_lock_irqsave(&allpstore_lock, flags); + spin_lock_irqsave(&records_list_lock, flags); list_del(&p->list); - spin_unlock_irqrestore(&allpstore_lock, flags); + spin_unlock_irqrestore(&records_list_lock, flags); free_pstore_private(p); } } @@ -302,8 +302,8 @@ int pstore_mkfile(struct dentry *root, struct pstore_record *record) WARN_ON(!inode_is_locked(d_inode(root))); - spin_lock_irqsave(&allpstore_lock, flags); - list_for_each_entry(pos, &allpstore, list) { + spin_lock_irqsave(&records_list_lock, flags); + list_for_each_entry(pos, &records_list, list) { if (pos->record->type == record->type && pos->record->id == record->id && pos->record->psi == record->psi) { @@ -311,7 +311,7 @@ int pstore_mkfile(struct dentry *root, struct pstore_record *record) break; } } - spin_unlock_irqrestore(&allpstore_lock, flags); + spin_unlock_irqrestore(&records_list_lock, flags); if (rc) return rc; @@ -343,9 +343,9 @@ int pstore_mkfile(struct dentry *root, struct pstore_record *record) d_add(dentry, inode); - spin_lock_irqsave(&allpstore_lock, flags); - list_add(&private->list, &allpstore); - spin_unlock_irqrestore(&allpstore_lock, flags); + spin_lock_irqsave(&records_list_lock, flags); + list_add(&private->list, &records_list); + spin_unlock_irqrestore(&records_list_lock, flags); return 0; From patchwork Wed May 6 15:21:09 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kees Cook X-Patchwork-Id: 1237017 Return-Path: Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 21F69C28CBC for ; Wed, 6 May 2020 15:21:56 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E9A8C20936 for ; Wed, 6 May 2020 15:21:55 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="SEOaL+ZT" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729493AbgEFPVz (ORCPT ); Wed, 6 May 2020 11:21:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58242 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729442AbgEFPVs (ORCPT ); Wed, 6 May 2020 11:21:48 -0400 Received: from mail-pf1-x441.google.com (mail-pf1-x441.google.com [IPv6:2607:f8b0:4864:20::441]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B7CC1C061A41 for ; Wed, 6 May 2020 08:21:48 -0700 (PDT) Received: by mail-pf1-x441.google.com with SMTP id f7so1132768pfa.9 for ; Wed, 06 May 2020 08:21:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=KnDu3tZEBuDEdkah0E91muUvxOc37NwJBlrIsTXyDX4=; b=SEOaL+ZTp6AU/8DsJmrVhdThhOeF+iFeYv4VY3pk/57OnoLmKbB6caoJgIgwJAfGS+ 3F0kvKXV0zV8FWf5cpsy+Gco8hcIIxOJaeBJYQaj0Su0tQXMUxDF0I/1T3AGyIRM6teK 22CfJXAbVu596XkudelUD0YRb+ssyRiWUc7Sk= 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=KnDu3tZEBuDEdkah0E91muUvxOc37NwJBlrIsTXyDX4=; b=lHstzrktiMDUJq3dOXC9O6bvmW6F67P8f0YdR7opcE1gMx2Lu/Qc4yt7lf8J/QxaiF ykkaQQU/Y3EgkrD6cKyOfB+ubTNlYhvd0V/JH7IsI0oGYZcXwXkEo7a2e6zKAykCjuoR avld0ia3xBX/5CwwuvSrK65FLKFzpEjx+gAK7mU7iXCQR7l2rrqcXe/U6z+SLILDI70z /3CYIKjKerhixnHA91QSa73otmB907pnEk5xOROrg6JjsMpM5sMj+ry3t8Q78FyZlRFN eoYiAMMEkx5eoyTjliyjr79uIHi/iWwfrSGt/MW6njXi8vFLWRgT/DOdzRf+9XbsGTKX bdow== X-Gm-Message-State: AGi0PuYlzyWVdaSOG+r2Qe2SmAPiJLXy6ViCw0IQuf3dxCu/YoWuqcdX KClDFnohsRDnZEdgFrWlOwiHmw== X-Google-Smtp-Source: APiQypIWSULl1oSen40Hk9tsVsH4QAL8lM3EbX1mpQ9nhUX5fAi4/jGssKYijSqyhBXKfx3iyjANtQ== X-Received: by 2002:aa7:808e:: with SMTP id v14mr8922923pff.168.1588778508246; Wed, 06 May 2020 08:21:48 -0700 (PDT) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id p1sm5360532pjf.15.2020.05.06.08.21.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 May 2020 08:21:45 -0700 (PDT) From: Kees Cook To: linux-kernel@vger.kernel.org Cc: Kees Cook , Anton Vorontsov , Colin Cross , Tony Luck , Luis Henriques Subject: [PATCH 05/10] pstore: Convert "records_list" locking to mutex Date: Wed, 6 May 2020 08:21:09 -0700 Message-Id: <20200506152114.50375-6-keescook@chromium.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200506152114.50375-1-keescook@chromium.org> References: <20200506152114.50375-1-keescook@chromium.org> MIME-Version: 1.0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The pstorefs internal list lock doesn't need to be a spinlock and will create problems when trying to access the list in the subsequent patch that will walk the pstorefs records during pstore_unregister(). Change this to a mutex to avoid may_sleep() warnings when unregistering devices. Signed-off-by: Kees Cook --- fs/pstore/inode.c | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/fs/pstore/inode.c b/fs/pstore/inode.c index 5cc09cb315f9..92ebcc75434f 100644 --- a/fs/pstore/inode.c +++ b/fs/pstore/inode.c @@ -22,14 +22,13 @@ #include #include #include -#include #include #include "internal.h" #define PSTORE_NAMELEN 64 -static DEFINE_SPINLOCK(records_list_lock); +static DEFINE_MUTEX(records_list_lock); static LIST_HEAD(records_list); struct pstore_private { @@ -192,13 +191,12 @@ static int pstore_unlink(struct inode *dir, struct dentry *dentry) static void pstore_evict_inode(struct inode *inode) { struct pstore_private *p = inode->i_private; - unsigned long flags; clear_inode(inode); if (p) { - spin_lock_irqsave(&records_list_lock, flags); + mutex_lock(&records_list_lock); list_del(&p->list); - spin_unlock_irqrestore(&records_list_lock, flags); + mutex_unlock(&records_list_lock); free_pstore_private(p); } } @@ -297,12 +295,11 @@ int pstore_mkfile(struct dentry *root, struct pstore_record *record) int rc = 0; char name[PSTORE_NAMELEN]; struct pstore_private *private, *pos; - unsigned long flags; size_t size = record->size + record->ecc_notice_size; WARN_ON(!inode_is_locked(d_inode(root))); - spin_lock_irqsave(&records_list_lock, flags); + mutex_lock(&records_list_lock); list_for_each_entry(pos, &records_list, list) { if (pos->record->type == record->type && pos->record->id == record->id && @@ -311,7 +308,7 @@ int pstore_mkfile(struct dentry *root, struct pstore_record *record) break; } } - spin_unlock_irqrestore(&records_list_lock, flags); + mutex_unlock(&records_list_lock); if (rc) return rc; @@ -343,9 +340,9 @@ int pstore_mkfile(struct dentry *root, struct pstore_record *record) d_add(dentry, inode); - spin_lock_irqsave(&records_list_lock, flags); + mutex_lock(&records_list_lock); list_add(&private->list, &records_list); - spin_unlock_irqrestore(&records_list_lock, flags); + mutex_unlock(&records_list_lock); return 0; From patchwork Wed May 6 15:21:10 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kees Cook X-Patchwork-Id: 1237022 Return-Path: Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 691F3C28CBC for ; Wed, 6 May 2020 15:22:15 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4320C20936 for ; Wed, 6 May 2020 15:22:15 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="n0RKQ4Pv" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729543AbgEFPWO (ORCPT ); Wed, 6 May 2020 11:22:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58230 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729432AbgEFPVs (ORCPT ); Wed, 6 May 2020 11:21:48 -0400 Received: from mail-pg1-x544.google.com (mail-pg1-x544.google.com [IPv6:2607:f8b0:4864:20::544]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4B775C061A0F for ; Wed, 6 May 2020 08:21:47 -0700 (PDT) Received: by mail-pg1-x544.google.com with SMTP id o18so916049pgg.8 for ; Wed, 06 May 2020 08:21:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=6FPHhltyts4CbjXyjzAz4UzPIGw8eB8kjsShSwpY9GA=; b=n0RKQ4Pvfh57lj8l+w7gRc28SobAcNrostqD2b+3d/Tm4/w1v7ec2dpBWqsALFCaFt mNozt1CXfQCJueFPxbU9SbxEbBmal9djZSkRG29EyWpcIpiJnPRFfBv+faC+IoD6wKCZ 8W7sKMBJKZCHAqKJ7fcpJQw0TyKK/+SUh65Oo= 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=6FPHhltyts4CbjXyjzAz4UzPIGw8eB8kjsShSwpY9GA=; b=bAeoCmeNYTrmIcSYWQJlYHvlrQB2A4Wn4iVXM/dyxuotn60Tk7jayu+8Jw28Y02XF5 Prz5P5if9N1SQ/hF4zh8g54bLmYc1zquS0GhnYL56jCTiLOPIXIxa/MsPvcta0bwfLtw V6hfv6jiRibRiG868EcAx2o5w8EeXzgDJ2JUIEOU3PsCpgW/meZyYrN46Os1/ojL0ERd eESLIRe+fty+rL6GN7jPFfwZlXrrFS1s9Ef8lfohqtjxVoiJA2Sd26XrSdCcxr5iR63T s7dXLndztx4Za6lMRH0vJxKLSGWUdhf2GSVxrxYFakB3rqu9QGJzlVQ4m7LQmgPOMJjH Yg1A== X-Gm-Message-State: AGi0PuZZEtzvXtgwXMIIiqMcIWVu3OFIt58MJcuf9E1+nOaUDBjjyldj doyEcRq/h3caq6g8MZMTRyh/Mg== X-Google-Smtp-Source: APiQypLh9RvGoT0iwrPdwog7Mjn6D6HHWosykg+YX13mR5pqaXMKMBjVJQn6T/AVtBF9pPq01E4uTA== X-Received: by 2002:a62:1bd0:: with SMTP id b199mr8648232pfb.283.1588778506852; Wed, 06 May 2020 08:21:46 -0700 (PDT) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id a2sm2130015pfg.106.2020.05.06.08.21.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 May 2020 08:21:45 -0700 (PDT) From: Kees Cook To: linux-kernel@vger.kernel.org Cc: Kees Cook , Anton Vorontsov , Colin Cross , Tony Luck , Luis Henriques Subject: [PATCH 06/10] pstore: Add proper unregister lock checking Date: Wed, 6 May 2020 08:21:10 -0700 Message-Id: <20200506152114.50375-7-keescook@chromium.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200506152114.50375-1-keescook@chromium.org> References: <20200506152114.50375-1-keescook@chromium.org> MIME-Version: 1.0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The pstore backend lock wasn't being used during pstore_unregister(). Add sanity check and locking. Signed-off-by: Kees Cook --- fs/pstore/platform.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/fs/pstore/platform.c b/fs/pstore/platform.c index d0ce22237589..03bc847a6951 100644 --- a/fs/pstore/platform.c +++ b/fs/pstore/platform.c @@ -69,8 +69,9 @@ static void pstore_dowork(struct work_struct *); static DECLARE_WORK(pstore_work, pstore_dowork); /* - * psinfo_lock just protects "psinfo" during - * calls to pstore_register() + * psinfo_lock protects "psinfo" during calls to + * pstore_register(), pstore_unregister(), and + * the filesystem mount/unmount routines. */ static DEFINE_MUTEX(psinfo_lock); struct pstore_info *psinfo; @@ -626,6 +627,18 @@ EXPORT_SYMBOL_GPL(pstore_register); void pstore_unregister(struct pstore_info *psi) { + /* It's okay to unregister nothing. */ + if (!psi) + return; + + mutex_lock(&psinfo_lock); + + /* Only one backend can be registered at a time. */ + if (WARN_ON(psi != psinfo)) { + mutex_unlock(&psinfo_lock); + return; + } + /* Stop timer and make sure all work has finished. */ pstore_update_ms = -1; del_timer_sync(&pstore_timer); @@ -644,6 +657,7 @@ void pstore_unregister(struct pstore_info *psi) psinfo = NULL; backend = NULL; + mutex_unlock(&psinfo_lock); } EXPORT_SYMBOL_GPL(pstore_unregister); From patchwork Wed May 6 15:21:11 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kees Cook X-Patchwork-Id: 1237023 Return-Path: Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 71A01C28CBC for ; Wed, 6 May 2020 15:22:20 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 482D4215A4 for ; Wed, 6 May 2020 15:22:20 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="YL2uiFT8" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729552AbgEFPWT (ORCPT ); Wed, 6 May 2020 11:22:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58236 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729403AbgEFPVr (ORCPT ); Wed, 6 May 2020 11:21:47 -0400 Received: from mail-pf1-x444.google.com (mail-pf1-x444.google.com [IPv6:2607:f8b0:4864:20::444]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C8518C061A10 for ; Wed, 6 May 2020 08:21:47 -0700 (PDT) Received: by mail-pf1-x444.google.com with SMTP id x15so1151952pfa.1 for ; Wed, 06 May 2020 08:21:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=yYP6yxdymrxxL7hUVPNJiyuT/lyDa/+W7RPc1DbYPHc=; b=YL2uiFT8hDsK5U6H0DNA4rGJ4iLiS87bkVFGZgceoC5OLrZspZqhasZRGqHyw9vEAa s9XlnM/1Fn3F/Ij8OzmWwOgALL0FbKAuMoB8IBWoKEAcP5kn3DFrNWqQ5Y4KvvjCiS9O hKo3tqEoLGUCkJFXiNPcPscNPZHFDHpi3hemI= 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=yYP6yxdymrxxL7hUVPNJiyuT/lyDa/+W7RPc1DbYPHc=; b=WCLbnpYJ2wn76Zwd1rmYjXAseK/dpBTw8lf7pyet5CpYV+zCTtTpOPMUm7hV07LuBC kXSdenqos5wJxHu+D9wNk2LnrzAR8aAAHt+2bvw4dBapmyJIYne3TzE1SensmTIgz9ZZ UC+hMWvbnneDWFKlfA3R0Q1IgQ/IbaBWkQSdg9TE9BJyoxX+Ua2aTcmdTRPlhaDvi8wY wyFoYUrHbjutm3TtTYlKdnk/Y/0rvFitpiTxFF+6gRweP6zFVNXNbc4shlzhhVzIda3+ 8YgqRqaclKRmvjbYxCvaEN946bUTXibNBPk3RXaRo7ICy0qOmtGiSXGpESiS0gEwR6qc DSsg== X-Gm-Message-State: AGi0PuY7yA+1tT7hkNjc0mNHRIUAQy2ueaRsiQXndUlLeFR1IDNjpVZJ 80f9dnsKlHzPxycwbOsOgeJrHA== X-Google-Smtp-Source: APiQypKsPGQTXvWajEoICKm/o+r5Lp4Itu7fJOsuFBcfRstMYwMcoK8cNblDOotBDBm6wLDOYj2HBw== X-Received: by 2002:a62:f247:: with SMTP id y7mr8793849pfl.200.1588778507388; Wed, 06 May 2020 08:21:47 -0700 (PDT) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id t80sm2231606pfc.23.2020.05.06.08.21.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 May 2020 08:21:45 -0700 (PDT) From: Kees Cook To: linux-kernel@vger.kernel.org Cc: Kees Cook , Anton Vorontsov , Colin Cross , Tony Luck , Luis Henriques Subject: [PATCH 07/10] pstore: Refactor pstorefs record list removal Date: Wed, 6 May 2020 08:21:11 -0700 Message-Id: <20200506152114.50375-8-keescook@chromium.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200506152114.50375-1-keescook@chromium.org> References: <20200506152114.50375-1-keescook@chromium.org> MIME-Version: 1.0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The "unlink" handling should perform list removal (which can also make sure records don't get double-erased), and the "evict" handling should be responsible only for memory freeing. Signed-off-by: Kees Cook --- fs/pstore/inode.c | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/fs/pstore/inode.c b/fs/pstore/inode.c index 92ebcc75434f..5f08b21b7a46 100644 --- a/fs/pstore/inode.c +++ b/fs/pstore/inode.c @@ -177,10 +177,21 @@ static int pstore_unlink(struct inode *dir, struct dentry *dentry) { struct pstore_private *p = d_inode(dentry)->i_private; struct pstore_record *record = p->record; + int rc = 0; if (!record->psi->erase) return -EPERM; + /* Make sure we can't race while removing this file. */ + mutex_lock(&records_list_lock); + if (!list_empty(&p->list)) + list_del_init(&p->list); + else + rc = -ENOENT; + mutex_unlock(&records_list_lock); + if (rc) + return rc; + mutex_lock(&record->psi->read_mutex); record->psi->erase(record); mutex_unlock(&record->psi->read_mutex); @@ -193,12 +204,7 @@ static void pstore_evict_inode(struct inode *inode) struct pstore_private *p = inode->i_private; clear_inode(inode); - if (p) { - mutex_lock(&records_list_lock); - list_del(&p->list); - mutex_unlock(&records_list_lock); - free_pstore_private(p); - } + free_pstore_private(p); } static const struct inode_operations pstore_dir_inode_operations = { @@ -417,6 +423,7 @@ static void pstore_kill_sb(struct super_block *sb) { kill_litter_super(sb); pstore_sb = NULL; + INIT_LIST_HEAD(&records_list); } static struct file_system_type pstore_fs_type = { From patchwork Wed May 6 15:21:12 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kees Cook X-Patchwork-Id: 1237018 Return-Path: Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2B4D8C47256 for ; Wed, 6 May 2020 15:21:58 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 02F6520A8B for ; Wed, 6 May 2020 15:21:58 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="E4l5km+t" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729507AbgEFPV5 (ORCPT ); Wed, 6 May 2020 11:21:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58244 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729449AbgEFPVt (ORCPT ); Wed, 6 May 2020 11:21:49 -0400 Received: from mail-pl1-x644.google.com (mail-pl1-x644.google.com [IPv6:2607:f8b0:4864:20::644]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6B22FC0610D5 for ; Wed, 6 May 2020 08:21:49 -0700 (PDT) Received: by mail-pl1-x644.google.com with SMTP id x10so617963plr.4 for ; Wed, 06 May 2020 08:21:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=w8mOPg/WJbpwFq17aNXqVhrLVAgEDXC59soVlAVNO7M=; b=E4l5km+thT0FJN99T1qK6r+jZ/T1hE87pBpi1b0c57RVkyyrYY8hypmTzqsM9e1sQy dtGW9l83v1OHSz1rMVx4Oo67ORv+sI7FXVxG6lnvHhTmBLuSosSemsGxVEMjV4mgJoyq UX4wr1DxrKnVg/tYeIsPYBaQMjqJ0v4zQ1af4= 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=w8mOPg/WJbpwFq17aNXqVhrLVAgEDXC59soVlAVNO7M=; b=Lahz5HB/azPGPqUVR6B9misKeTKQVj4OpVRdd/rL4Uf8FPtmhVpKomdiqZFEffjvST 4YuaZelgyuaFSMMa6cyWMKtrvRBLfH6odY7SihMGVRArv02uHwz5iejKmA0AUJ7qPUbV MDXwrP0o/dOW5WYQDNJ6YFdY7cPFaFUrW1ccfI6qMheYjg1As1TyGqYFDC9SUncXSXqf udM0VLENrNPJV5b87pRSb+iwr0V99bF22xyAWm35Zu+4WC/ocrzu9NIHmhlfEHfS5mFG Nkzp0jJpBy3OAR7iGnoOYxHdMnEmX60G7Gv60I39p12JSDyq3LjDjyU1D1ebHT6oXEoB 8HbA== X-Gm-Message-State: AGi0PuaZxE/ah/6YKrTJy32DpWlnenBtWppmNhykugn/KsEt2VySM8yv PzvXjrOg5bZuNVPzpHBbKDEghQ== X-Google-Smtp-Source: APiQypImz2oOSfSE3NNLgEnKlJ1DyO7DE2gnMXI8IWGlXIr31bRhCeiiTy+8pWm2DPD63Dz7bYJfbw== X-Received: by 2002:a17:902:8a94:: with SMTP id p20mr582793plo.57.1588778508927; Wed, 06 May 2020 08:21:48 -0700 (PDT) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id r21sm4921156pjo.2.2020.05.06.08.21.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 May 2020 08:21:45 -0700 (PDT) From: Kees Cook To: linux-kernel@vger.kernel.org Cc: Kees Cook , Anton Vorontsov , Colin Cross , Tony Luck , Luis Henriques Subject: [PATCH 08/10] pstore: Add locking around superblock changes Date: Wed, 6 May 2020 08:21:12 -0700 Message-Id: <20200506152114.50375-9-keescook@chromium.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200506152114.50375-1-keescook@chromium.org> References: <20200506152114.50375-1-keescook@chromium.org> MIME-Version: 1.0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Nothing was protecting changes to the pstorefs superblock. Add locking and refactor away is_pstore_mounted(), instead using a helper to add a way to safely lock the pstorefs root inode during filesystem changes. Signed-off-by: Kees Cook --- fs/pstore/inode.c | 65 +++++++++++++++++++++++++++++--------------- fs/pstore/internal.h | 1 - fs/pstore/platform.c | 5 ++-- 3 files changed, 45 insertions(+), 26 deletions(-) diff --git a/fs/pstore/inode.c b/fs/pstore/inode.c index 5f08b21b7a46..e13482c8e180 100644 --- a/fs/pstore/inode.c +++ b/fs/pstore/inode.c @@ -31,6 +31,9 @@ static DEFINE_MUTEX(records_list_lock); static LIST_HEAD(records_list); +static DEFINE_MUTEX(pstore_sb_lock); +static struct super_block *pstore_sb; + struct pstore_private { struct list_head list; struct pstore_record *record; @@ -282,11 +285,25 @@ static const struct super_operations pstore_ops = { .show_options = pstore_show_options, }; -static struct super_block *pstore_sb; - -bool pstore_is_mounted(void) +struct dentry *psinfo_lock_root(void) { - return pstore_sb != NULL; + struct dentry *root; + + mutex_lock(&pstore_sb_lock); + /* + * Having no backend is fine -- no records appear. + * Not being mounted is fine -- nothing to do. + */ + if (!psinfo || !pstore_sb) { + mutex_unlock(&pstore_sb_lock); + return NULL; + } + + root = pstore_sb->s_root; + inode_lock(d_inode(root)); + mutex_unlock(&pstore_sb_lock); + + return root; } /* @@ -303,20 +320,18 @@ int pstore_mkfile(struct dentry *root, struct pstore_record *record) struct pstore_private *private, *pos; size_t size = record->size + record->ecc_notice_size; - WARN_ON(!inode_is_locked(d_inode(root))); + if (WARN_ON(!inode_is_locked(d_inode(root)))) + return -EINVAL; + rc = -EEXIST; + /* Skip records that are already present in the filesystem. */ mutex_lock(&records_list_lock); list_for_each_entry(pos, &records_list, list) { if (pos->record->type == record->type && pos->record->id == record->id && - pos->record->psi == record->psi) { - rc = -EEXIST; - break; - } + pos->record->psi == record->psi) + goto fail; } - mutex_unlock(&records_list_lock); - if (rc) - return rc; rc = -ENOMEM; inode = pstore_get_inode(root->d_sb); @@ -346,7 +361,6 @@ int pstore_mkfile(struct dentry *root, struct pstore_record *record) d_add(dentry, inode); - mutex_lock(&records_list_lock); list_add(&private->list, &records_list); mutex_unlock(&records_list_lock); @@ -356,8 +370,8 @@ int pstore_mkfile(struct dentry *root, struct pstore_record *record) free_pstore_private(private); fail_inode: iput(inode); - fail: + mutex_unlock(&records_list_lock); return rc; } @@ -369,16 +383,13 @@ int pstore_mkfile(struct dentry *root, struct pstore_record *record) */ void pstore_get_records(int quiet) { - struct pstore_info *psi = psinfo; struct dentry *root; - if (!psi || !pstore_sb) + root = psinfo_lock_root(); + if (!root) return; - root = pstore_sb->s_root; - - inode_lock(d_inode(root)); - pstore_get_backend_records(psi, root, quiet); + pstore_get_backend_records(psinfo, root, quiet); inode_unlock(d_inode(root)); } @@ -386,8 +397,6 @@ static int pstore_fill_super(struct super_block *sb, void *data, int silent) { struct inode *inode; - pstore_sb = sb; - sb->s_maxbytes = MAX_LFS_FILESIZE; sb->s_blocksize = PAGE_SIZE; sb->s_blocksize_bits = PAGE_SHIFT; @@ -408,6 +417,10 @@ static int pstore_fill_super(struct super_block *sb, void *data, int silent) if (!sb->s_root) return -ENOMEM; + mutex_lock(&pstore_sb_lock); + pstore_sb = sb; + mutex_unlock(&pstore_sb_lock); + pstore_get_records(0); return 0; @@ -421,9 +434,17 @@ static struct dentry *pstore_mount(struct file_system_type *fs_type, static void pstore_kill_sb(struct super_block *sb) { + mutex_lock(&pstore_sb_lock); + WARN_ON(pstore_sb != sb); + kill_litter_super(sb); pstore_sb = NULL; + + mutex_lock(&records_list_lock); INIT_LIST_HEAD(&records_list); + mutex_unlock(&records_list_lock); + + mutex_unlock(&pstore_sb_lock); } static struct file_system_type pstore_fs_type = { diff --git a/fs/pstore/internal.h b/fs/pstore/internal.h index 7062ea4bc57c..fe5f7ef7323f 100644 --- a/fs/pstore/internal.h +++ b/fs/pstore/internal.h @@ -33,7 +33,6 @@ extern void pstore_get_backend_records(struct pstore_info *psi, struct dentry *root, int quiet); extern int pstore_mkfile(struct dentry *root, struct pstore_record *record); -extern bool pstore_is_mounted(void); extern void pstore_record_init(struct pstore_record *record, struct pstore_info *psi); diff --git a/fs/pstore/platform.c b/fs/pstore/platform.c index 03bc847a6951..55f46837a7f4 100644 --- a/fs/pstore/platform.c +++ b/fs/pstore/platform.c @@ -460,7 +460,7 @@ static void pstore_dump(struct kmsg_dumper *dumper, } ret = psinfo->write(&record); - if (ret == 0 && reason == KMSG_DUMP_OOPS && pstore_is_mounted()) + if (ret == 0 && reason == KMSG_DUMP_OOPS) pstore_new_entry = 1; total += record.size; @@ -594,8 +594,7 @@ int pstore_register(struct pstore_info *psi) if (psi->flags & PSTORE_FLAGS_DMESG) allocate_buf_for_compression(); - if (pstore_is_mounted()) - pstore_get_records(0); + pstore_get_records(0); if (psi->flags & PSTORE_FLAGS_DMESG) pstore_register_kmsg(); From patchwork Wed May 6 15:21:13 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kees Cook X-Patchwork-Id: 1237019 Return-Path: Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id EC0DEC28CBC for ; Wed, 6 May 2020 15:22:00 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C761D20936 for ; Wed, 6 May 2020 15:22:00 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="kPtoH17W" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729518AbgEFPV7 (ORCPT ); Wed, 6 May 2020 11:21:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58254 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729475AbgEFPVv (ORCPT ); Wed, 6 May 2020 11:21:51 -0400 Received: from mail-pg1-x543.google.com (mail-pg1-x543.google.com [IPv6:2607:f8b0:4864:20::543]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2A6AAC061A0F for ; Wed, 6 May 2020 08:21:51 -0700 (PDT) Received: by mail-pg1-x543.google.com with SMTP id l12so909879pgr.10 for ; Wed, 06 May 2020 08:21:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Q0K/lv5zGYyr82mHQzUYrmx/oxfMBXzRZFC8ZU0cokw=; b=kPtoH17WkQd61pRXa7oPU+5nNu/1tOIwbo0X5iltCrgz2x55XhK9IkHhRBZax+/hPn RQaXT11HlV17Qsaww9Zx7Hy0rCQQht4TZKq2ixUgrjQ5uQ0T6UBmuuFEn7VrFfCdHDpd 0+Xzaj7d6hIrmiOBPVeQZ80HZQeecxnfjBH40= 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=Q0K/lv5zGYyr82mHQzUYrmx/oxfMBXzRZFC8ZU0cokw=; b=TRwdENyVLiAZM5NBPoqlovBqiPFtwOmIgNhkqANLD3pcOqJAhR44d1xzEKVfE19TUU B364ONaGXDeP5w87wQnnZ8X0GlXwTsskF7BZpWWwkBorUPnZbUSUgwA6AygdLY2+D6qe ziXW0Zmfz8mXubSP1900DTlUlg1uuqu8MxHASSLLnze2E0RwFqg8qn1IEu30xj/+m3PH aA2SDh0S+tVNIM19Nypxvx4gE0OVFIpXmZWuD6YLtx43I0x1yND2qo3jK82m3vog+VvJ G+L0vJjQ8uhbk6VXCwdsCwCoEOuDMkvP2ErdJQU/4wRVRjVMwk0kv3EJP60ywUb+ra7N 2KkA== X-Gm-Message-State: AGi0PuY3cnd+02mG2TGPVO3jz+pzhuH/PsiiZRk/kkpdKyj01NUIpL3P G05TOVyAwwBPYs6+10Tv2RTHK7/jqEU= X-Google-Smtp-Source: APiQypKNchaOE6ot5taOOUNgl3Z8z+GYVPXEzgFz1dmxosOo9OHMPnXGr4EpN87kFA2OoZmLG6BE+g== X-Received: by 2002:a62:f247:: with SMTP id y7mr8794147pfl.200.1588778510702; Wed, 06 May 2020 08:21:50 -0700 (PDT) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id h13sm1752842pgm.69.2020.05.06.08.21.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 May 2020 08:21:45 -0700 (PDT) From: Kees Cook To: linux-kernel@vger.kernel.org Cc: Kees Cook , Anton Vorontsov , Colin Cross , Tony Luck , Luis Henriques Subject: [PATCH 09/10] pstore: Do not leave timer disabled for next backend Date: Wed, 6 May 2020 08:21:13 -0700 Message-Id: <20200506152114.50375-10-keescook@chromium.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200506152114.50375-1-keescook@chromium.org> References: <20200506152114.50375-1-keescook@chromium.org> MIME-Version: 1.0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The pstore.update_ms value was being disabled during pstore_unregister(), which would cause any prior value to go unnoticed on the next pstore_register(). Instead, just let del_timer() stop the timer, which was always sufficient. This additionally refactors the timer reset code and allows the timer to be enabled if the module parameter is changed away from the default. Signed-off-by: Kees Cook --- fs/pstore/platform.c | 34 +++++++++++++++++++--------------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/fs/pstore/platform.c b/fs/pstore/platform.c index 55f46837a7f4..03a17b401533 100644 --- a/fs/pstore/platform.c +++ b/fs/pstore/platform.c @@ -44,7 +44,7 @@ static int pstore_update_ms = -1; module_param_named(update_ms, pstore_update_ms, int, 0600); MODULE_PARM_DESC(update_ms, "milliseconds before pstore updates its content " "(default is -1, which means runtime updates are disabled; " - "enabling this option is not safe, it may lead to further " + "enabling this option may not be safe; it may lead to further " "corruption on Oopses)"); /* Names should be in the same order as the enum pstore_type_id */ @@ -150,6 +150,14 @@ static const char *get_reason_str(enum kmsg_dump_reason reason) } } +static void pstore_timer_kick(void) +{ + if (pstore_update_ms < 0) + return; + + mod_timer(&pstore_timer, jiffies + msecs_to_jiffies(pstore_update_ms)); +} + /* * Should pstore_dump() wait for a concurrent pstore_dump()? If * not, the current pstore_dump() will report a failure to dump @@ -460,8 +468,10 @@ static void pstore_dump(struct kmsg_dumper *dumper, } ret = psinfo->write(&record); - if (ret == 0 && reason == KMSG_DUMP_OOPS) + if (ret == 0 && reason == KMSG_DUMP_OOPS) { pstore_new_entry = 1; + pstore_timer_kick(); + } total += record.size; part++; @@ -606,11 +616,7 @@ int pstore_register(struct pstore_info *psi) pstore_register_pmsg(); /* Start watching for new records, if desired. */ - if (pstore_update_ms >= 0) { - pstore_timer.expires = jiffies + - msecs_to_jiffies(pstore_update_ms); - add_timer(&pstore_timer); - } + pstore_timer_kick(); /* * Update the module parameter backend, so it is visible @@ -638,11 +644,7 @@ void pstore_unregister(struct pstore_info *psi) return; } - /* Stop timer and make sure all work has finished. */ - pstore_update_ms = -1; - del_timer_sync(&pstore_timer); - flush_work(&pstore_work); - + /* Unregister all callbacks. */ if (psi->flags & PSTORE_FLAGS_PMSG) pstore_unregister_pmsg(); if (psi->flags & PSTORE_FLAGS_FTRACE) @@ -652,6 +654,10 @@ void pstore_unregister(struct pstore_info *psi) if (psi->flags & PSTORE_FLAGS_DMESG) pstore_unregister_kmsg(); + /* Stop timer and make sure all work has finished. */ + del_timer_sync(&pstore_timer); + flush_work(&pstore_work); + free_buf_for_compression(); psinfo = NULL; @@ -793,9 +799,7 @@ static void pstore_timefunc(struct timer_list *unused) schedule_work(&pstore_work); } - if (pstore_update_ms >= 0) - mod_timer(&pstore_timer, - jiffies + msecs_to_jiffies(pstore_update_ms)); + pstore_timer_kick(); } static void __init pstore_choose_compression(void) From patchwork Wed May 6 15:21:14 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kees Cook X-Patchwork-Id: 1237021 Return-Path: Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id F34D8C28CBC for ; Wed, 6 May 2020 15:22:11 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D393020836 for ; Wed, 6 May 2020 15:22:11 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="NwE6Cmyt" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729535AbgEFPWK (ORCPT ); Wed, 6 May 2020 11:22:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58252 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729454AbgEFPVu (ORCPT ); Wed, 6 May 2020 11:21:50 -0400 Received: from mail-pl1-x642.google.com (mail-pl1-x642.google.com [IPv6:2607:f8b0:4864:20::642]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 079FEC061A0F for ; Wed, 6 May 2020 08:21:50 -0700 (PDT) Received: by mail-pl1-x642.google.com with SMTP id f8so620560plt.2 for ; Wed, 06 May 2020 08:21:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=ERUWIfdOS9Cj0+BLPXW5aMS+Ag/wqQVbo+Lakxt+p9w=; b=NwE6Cmytxmng/k7TS8r+iw6OzdunDB+XANkla0hlb1btZAm9RQaV5b4QkRbHgQfIzF g63fy0r0ifyQS1Qm/v+kM5dvZsFAA9+Frk/sTUU4KjWPI3cCG3kliHa3gNBLEyr8VL1G UDHsA8QOkjG39vEBy02FivrKgKNtjP4p7RhI0= 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=ERUWIfdOS9Cj0+BLPXW5aMS+Ag/wqQVbo+Lakxt+p9w=; b=SBzGiYBh7Nv12R58FSvVkwxN7xIxFlstdEfOAv5qcbFVcdoxvHgUVLZ2/SE8hjtaj3 ODDofHLB0LcnJjfA1uIatzaqO/Gsg+3GflM27hsJFySQ+oL+tk5oeJckpKA5M96VMOmD 7D15A4rwKVK/C7101WXaoS+iA5kEtME38se8atuOdQnQRXnNPFhS52/F6BjLffHqrYb4 KyrCQZDr/uaazYSuJP1rPTToO+3JcZ2xisYUCSiHWTzWrUKxqYJUqyEp3jIUVcNFPTdL kAQ3nyc4zcges+osSIKDCu/oVmZB8qNQUCfjnkmwaNZ8h2l4mGQNKyuKkQFeyTWBdreD nKKA== X-Gm-Message-State: AGi0PuafnNoTkAamaBfCX7OSt71zlFpAqwOobigk0wQxgKfJ2oGr6NTH KzrfhMfyYCCtHHFPLJfP4q5jAA== X-Google-Smtp-Source: APiQypLJ3ehC3xsgpfYaecchyxZdis0SCrOnZ0jKW7QF2tBHXpNTEnDnuXpozvvGmyRXq9CbaGcm0Q== X-Received: by 2002:a17:902:eb12:: with SMTP id l18mr8259388plb.239.1588778509550; Wed, 06 May 2020 08:21:49 -0700 (PDT) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id d2sm2153258pfc.7.2020.05.06.08.21.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 May 2020 08:21:45 -0700 (PDT) From: Kees Cook To: linux-kernel@vger.kernel.org Cc: Kees Cook , Luis Henriques , Anton Vorontsov , Colin Cross , Tony Luck Subject: [PATCH 10/10] pstore: Remove filesystem records when backend is unregistered Date: Wed, 6 May 2020 08:21:14 -0700 Message-Id: <20200506152114.50375-11-keescook@chromium.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200506152114.50375-1-keescook@chromium.org> References: <20200506152114.50375-1-keescook@chromium.org> MIME-Version: 1.0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org If a backend was unloaded without having first removed all its associated records in pstorefs, subsequent removals would crash while attempting to call into the now missing backend. Add automatic removal from the tree in pstore_unregister(), so that no references to the backend remain. Reported-by: Luis Henriques Link: https://lore.kernel.org/lkml/87o8yrmv69.fsf@suse.com Signed-off-by: Kees Cook --- fs/pstore/inode.c | 30 ++++++++++++++++++++++++++++++ fs/pstore/internal.h | 1 + fs/pstore/platform.c | 3 +++ 3 files changed, 34 insertions(+) diff --git a/fs/pstore/inode.c b/fs/pstore/inode.c index e13482c8e180..499d91a669bb 100644 --- a/fs/pstore/inode.c +++ b/fs/pstore/inode.c @@ -36,6 +36,7 @@ static struct super_block *pstore_sb; struct pstore_private { struct list_head list; + struct dentry *dentry; struct pstore_record *record; size_t total_size; }; @@ -306,6 +307,34 @@ struct dentry *psinfo_lock_root(void) return root; } +int pstore_put_backend_records(struct pstore_info *psi) +{ + struct pstore_private *pos, *tmp; + struct dentry *root; + int rc = 0; + + root = psinfo_lock_root(); + if (!root) + return 0; + + mutex_lock(&records_list_lock); + list_for_each_entry_safe(pos, tmp, &records_list, list) { + if (pos->record->psi == psi) { + list_del_init(&pos->list); + rc = simple_unlink(d_inode(root), pos->dentry); + if (WARN_ON(rc)) + break; + d_delete(pos->dentry); + dput(pos->dentry); + } + } + mutex_unlock(&records_list_lock); + + inode_unlock(d_inode(root)); + + return rc; +} + /* * Make a regular file in the root directory of our file system. * Load it up with "size" bytes of data from "buf". @@ -352,6 +381,7 @@ int pstore_mkfile(struct dentry *root, struct pstore_record *record) if (!dentry) goto fail_private; + private->dentry = dentry; private->record = record; inode->i_size = private->total_size = size; inode->i_private = private; diff --git a/fs/pstore/internal.h b/fs/pstore/internal.h index fe5f7ef7323f..8efd72d93b10 100644 --- a/fs/pstore/internal.h +++ b/fs/pstore/internal.h @@ -31,6 +31,7 @@ extern void pstore_set_kmsg_bytes(int); extern void pstore_get_records(int); extern void pstore_get_backend_records(struct pstore_info *psi, struct dentry *root, int quiet); +extern int pstore_put_backend_records(struct pstore_info *psi); extern int pstore_mkfile(struct dentry *root, struct pstore_record *record); extern void pstore_record_init(struct pstore_record *record, diff --git a/fs/pstore/platform.c b/fs/pstore/platform.c index 03a17b401533..6fb526187953 100644 --- a/fs/pstore/platform.c +++ b/fs/pstore/platform.c @@ -658,6 +658,9 @@ void pstore_unregister(struct pstore_info *psi) del_timer_sync(&pstore_timer); flush_work(&pstore_work); + /* Remove all backend records from filesystem tree. */ + pstore_put_backend_records(psi); + free_buf_for_compression(); psinfo = NULL;