From patchwork Thu Apr 14 05:43:24 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiubo Li X-Patchwork-Id: 561971 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 9BC7CC433F5 for ; Thu, 14 Apr 2022 05:43:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234133AbiDNFqD (ORCPT ); Thu, 14 Apr 2022 01:46:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41470 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231251AbiDNFqD (ORCPT ); Thu, 14 Apr 2022 01:46:03 -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 ESMTP id AE38349F0A for ; Wed, 13 Apr 2022 22:43:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1649915018; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=adBYNiofK6H6nKjsEB57TrQzmk/JV8QiRaDMMGegPRE=; b=LghotsQ2GXULF1IFOEMkRKte+/RlsEDOEV6+Rp1CI8nnlwSggC0aVOLOD9NSO3HLyiEsii IMds7NxwcqS16BG12/cakjdkCMD9dRHoUqgsuDMUEYYd7NtY9j7z6sxrDcI1syZUmUaV8P gQ7KRhiS9HvE0V6yii9kPKmPfEDsfyU= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-184-Yb6OSukaMUuozt_9wOWsmg-1; Thu, 14 Apr 2022 01:43:34 -0400 X-MC-Unique: Yb6OSukaMUuozt_9wOWsmg-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 2EE6F802803; Thu, 14 Apr 2022 05:43:34 +0000 (UTC) Received: from localhost (unknown [10.72.47.117]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8A44640F4940; Thu, 14 Apr 2022 05:43:33 +0000 (UTC) From: Xiubo Li To: jlayton@kernel.org Cc: idryomov@gmail.com, vshankar@redhat.com, ceph-devel@vger.kernel.org, Xiubo Li Subject: [PATCH] ceph: fix possible NULL pointer dereference for req->r_session Date: Thu, 14 Apr 2022 13:43:24 +0800 Message-Id: <20220414054324.374694-1-xiubli@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.11.54.2 Precedence: bulk List-ID: X-Mailing-List: ceph-devel@vger.kernel.org The request will be inserted into the ci->i_unsafe_dirops before assigning the req->r_session, so it's possible that we will hit NULL pointer dereference bug here. URL: https://tracker.ceph.com/issues/55327 Signed-off-by: Xiubo Li --- fs/ceph/caps.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/fs/ceph/caps.c b/fs/ceph/caps.c index 69af17df59be..6a9bf58478c8 100644 --- a/fs/ceph/caps.c +++ b/fs/ceph/caps.c @@ -2333,7 +2333,7 @@ static int unsafe_request_wait(struct inode *inode) list_for_each_entry(req, &ci->i_unsafe_dirops, r_unsafe_dir_item) { s = req->r_session; - if (unlikely(s->s_mds >= max_sessions)) { + if (unlikely(s && s->s_mds >= max_sessions)) { spin_unlock(&ci->i_unsafe_lock); for (i = 0; i < max_sessions; i++) { s = sessions[i]; @@ -2343,7 +2343,7 @@ static int unsafe_request_wait(struct inode *inode) kfree(sessions); goto retry; } - if (!sessions[s->s_mds]) { + if (s && !sessions[s->s_mds]) { s = ceph_get_mds_session(s); sessions[s->s_mds] = s; } @@ -2353,7 +2353,7 @@ static int unsafe_request_wait(struct inode *inode) list_for_each_entry(req, &ci->i_unsafe_iops, r_unsafe_target_item) { s = req->r_session; - if (unlikely(s->s_mds >= max_sessions)) { + if (unlikely(s && s->s_mds >= max_sessions)) { spin_unlock(&ci->i_unsafe_lock); for (i = 0; i < max_sessions; i++) { s = sessions[i]; @@ -2363,7 +2363,7 @@ static int unsafe_request_wait(struct inode *inode) kfree(sessions); goto retry; } - if (!sessions[s->s_mds]) { + if (s && !sessions[s->s_mds]) { s = ceph_get_mds_session(s); sessions[s->s_mds] = s; }