From patchwork Wed Oct 11 14:38:46 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Namjae Jeon X-Patchwork-Id: 1846800 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=2620:137:e000::1:20; helo=out1.vger.email; envelope-from=linux-cifs-owner@vger.kernel.org; receiver=patchwork.ozlabs.org) Received: from out1.vger.email (out1.vger.email [IPv6:2620:137:e000::1:20]) by legolas.ozlabs.org (Postfix) with ESMTP id 4S5Fy55v0Jz23jd for ; Thu, 12 Oct 2023 01:48:29 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346706AbjJKOs0 (ORCPT ); Wed, 11 Oct 2023 10:48:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40084 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235041AbjJKOs0 (ORCPT ); Wed, 11 Oct 2023 10:48:26 -0400 Received: from mail-pf1-f172.google.com (mail-pf1-f172.google.com [209.85.210.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D839794 for ; Wed, 11 Oct 2023 07:48:24 -0700 (PDT) Received: by mail-pf1-f172.google.com with SMTP id d2e1a72fcca58-690bf8fdd1aso5233102b3a.2 for ; Wed, 11 Oct 2023 07:48:24 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697035704; x=1697640504; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=IEGkN6P6TCIB4ESVyJmdYOmltlDozsLBHrVEFqMYCWM=; b=GplxlU971cXv5YE7A9z+rpX1Q1C8uEEOlCu/PrySgx+80S86gLxNMt8LJVpJuOZvdb nG43bCbbxAJRoJUnzzGW1AlO3eMW2r7tCeFJwA/TtAGqOA3pCPlgUDNDIxvXH9rMGivj AkGhXqguRuUkvx9WT+gb1PfT19ENs8SNCdWYX1gLGZEcqtLTmsNaeSMl0J15azaUVz6Y vbphstnpiKt6SPqlO96+6BbLbx1TSWmdZQmw6UEvnKidB4QkESelw1XfJKuCX3zFKJc/ NOtXmKN6tPv0L0Agb49uBrlroRL6n/vZs9qV31kLM/1ZLZdiVkAXBjAC+OIAlv3LqipV ydiw== X-Gm-Message-State: AOJu0YwnD0QwJiyN7dd56g/6czIS5QQJD/R7Q1lHLvgFwCUptZYsMyx5 noDcXrnp4N9OueSYvNRBMT9CUC8TsRc= X-Google-Smtp-Source: AGHT+IGOHAqIzx3MxKDuF+hfdYbjGtUoP4hS5zXnrm/9d5lPZo/IIAuyehozTfRwULwYDWfo1kEnQw== X-Received: by 2002:a05:6a00:180c:b0:690:d008:8cfc with SMTP id y12-20020a056a00180c00b00690d0088cfcmr24131307pfa.32.1697035703766; Wed, 11 Oct 2023 07:48:23 -0700 (PDT) Received: from localhost.localdomain ([110.14.71.32]) by smtp.gmail.com with ESMTPSA id ey5-20020a056a0038c500b0068ff6d21563sm10626059pfb.148.2023.10.11.07.48.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Oct 2023 07:48:23 -0700 (PDT) From: Namjae Jeon To: linux-cifs@vger.kernel.org Cc: smfrench@gmail.com, senozhatsky@chromium.org, tom@talpey.com, atteh.mailbox@gmail.com, Namjae Jeon , Coverity Scan Subject: [PATCH 1/2] ksmbd: fix Null pointer dereferences in ksmbd_update_fstate() Date: Wed, 11 Oct 2023 23:38:46 +0900 Message-Id: <20231011143847.9140-1-linkinjeon@kernel.org> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 X-Spam-Status: No, score=-1.4 required=5.0 tests=BAYES_00, FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS, RCVD_IN_DNSWL_BLOCKED,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-cifs@vger.kernel.org Coverity Scan report the following one. This report is a false alarm. Because fp is never NULL when rc is zero. This patch add null check for fp in ksmbd_update_fstate to make alarm silence. *** CID 1568583: Null pointer dereferences (FORWARD_NULL) /fs/smb/server/smb2pdu.c: 3408 in smb2_open() 3402 path_put(&path); 3403 path_put(&parent_path); 3404 } 3405 ksmbd_revert_fsids(work); 3406 err_out1: 3407 if (!rc) { >>> CID 1568583: Null pointer dereferences (FORWARD_NULL) >>> Passing null pointer "fp" to "ksmbd_update_fstate", which dereferences it. 3408 ksmbd_update_fstate(&work->sess->file_table, fp, FP_INITED); 3409 rc = ksmbd_iov_pin_rsp(work, (void *)rsp, iov_len); 3410 } 3411 if (rc) { 3412 if (rc == -EINVAL) 3413 rsp->hdr.Status = STATUS_INVALID_PARAMETER; Fixes: e2b76ab8b5c9 ("ksmbd: add support for read compound") Reported-by: Coverity Scan Signed-off-by: Namjae Jeon --- fs/smb/server/vfs_cache.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/fs/smb/server/vfs_cache.c b/fs/smb/server/vfs_cache.c index 1c5c39733652..c91eac6514dd 100644 --- a/fs/smb/server/vfs_cache.c +++ b/fs/smb/server/vfs_cache.c @@ -603,6 +603,9 @@ struct ksmbd_file *ksmbd_open_fd(struct ksmbd_work *work, struct file *filp) void ksmbd_update_fstate(struct ksmbd_file_table *ft, struct ksmbd_file *fp, unsigned int state) { + if (!fp) + return; + write_lock(&ft->lock); fp->f_state = state; write_unlock(&ft->lock); From patchwork Wed Oct 11 14:38:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Namjae Jeon X-Patchwork-Id: 1846801 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=2620:137:e000::1:20; helo=out1.vger.email; envelope-from=linux-cifs-owner@vger.kernel.org; receiver=patchwork.ozlabs.org) Received: from out1.vger.email (out1.vger.email [IPv6:2620:137:e000::1:20]) by legolas.ozlabs.org (Postfix) with ESMTP id 4S5FyJ3yv2z23jd for ; Thu, 12 Oct 2023 01:48:40 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232246AbjJKOsk (ORCPT ); Wed, 11 Oct 2023 10:48:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52942 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235041AbjJKOsj (ORCPT ); Wed, 11 Oct 2023 10:48:39 -0400 Received: from mail-oo1-f48.google.com (mail-oo1-f48.google.com [209.85.161.48]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CF688BA for ; Wed, 11 Oct 2023 07:48:37 -0700 (PDT) Received: by mail-oo1-f48.google.com with SMTP id 006d021491bc7-57b68556d6dso3835031eaf.1 for ; Wed, 11 Oct 2023 07:48:37 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697035717; x=1697640517; 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=KWq5BS6S9RabcE2DIs2WK/cbdGqkeRiKmjdiZPxBiYI=; b=MxvJHrIrxuUYCq1ZDhHRpt+ABoWhOxwa4O03KoNLZpM4LxM+LKSj8QtUodp8fAhWLF u7TwBS7/2XQtdS3mYlTeaYh/Hnb1+pVPL0DD5tCa8BtMoyuCrOG5zwSc3dqS4CH1w0V/ l5LV0XuLD7Kb32e3gkr5hUUqLQ/kYETjEJhs7nyHh+Wkzh5Zwacku9KjAkRVmkrltVXu boy1fo9ZboduFrD4TDrtbL47JvqCI7IMKM90aYF+gVwjef95fhR00572k4mB+JhF+zX4 7ciSJdHMQHJWxRL1h7wMJ65ybLNC9xcpYjhvqgTXPokENu/DMgMmaKF1RRPtT4DejAh9 8Ueg== X-Gm-Message-State: AOJu0YzfSabfMagohLD8ImhKLNgiRu0oCZRJ+74vrGliA5/ynREgtXj6 0s1V9CDwltLpjeQslnBNIutj6y7vm/4= X-Google-Smtp-Source: AGHT+IH8i/z39sjATbkcmKdLik2AvpBxzigNcMMiQA5hKFJoWHrjRfEyc3ibC7QwfUA6ScjR8Tzy7A== X-Received: by 2002:a05:6358:3421:b0:14d:bad5:6adf with SMTP id h33-20020a056358342100b0014dbad56adfmr24126847rwd.21.1697035716659; Wed, 11 Oct 2023 07:48:36 -0700 (PDT) Received: from localhost.localdomain ([110.14.71.32]) by smtp.gmail.com with ESMTPSA id ey5-20020a056a0038c500b0068ff6d21563sm10626059pfb.148.2023.10.11.07.48.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Oct 2023 07:48:36 -0700 (PDT) From: Namjae Jeon To: linux-cifs@vger.kernel.org Cc: smfrench@gmail.com, senozhatsky@chromium.org, tom@talpey.com, atteh.mailbox@gmail.com, Namjae Jeon , kernel test robot , Dan Carpenter Subject: [PATCH 2/2] ksmbd: fix potential double free on smb2_read_pipe() error path Date: Wed, 11 Oct 2023 23:38:47 +0900 Message-Id: <20231011143847.9140-2-linkinjeon@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20231011143847.9140-1-linkinjeon@kernel.org> References: <20231011143847.9140-1-linkinjeon@kernel.org> MIME-Version: 1.0 X-Spam-Status: No, score=-1.4 required=5.0 tests=BAYES_00, FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS, RCVD_IN_DNSWL_BLOCKED,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL, SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-cifs@vger.kernel.org Fix new smatch warnings: fs/smb/server/smb2pdu.c:6131 smb2_read_pipe() error: double free of 'rpc_resp' Fixes: e2b76ab8b5c9 ("ksmbd: add support for read compound") Reported-by: kernel test robot Reported-by: Dan Carpenter Signed-off-by: Namjae Jeon --- fs/smb/server/smb2pdu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fs/smb/server/smb2pdu.c b/fs/smb/server/smb2pdu.c index 87c6401a6007..93262ca3f58a 100644 --- a/fs/smb/server/smb2pdu.c +++ b/fs/smb/server/smb2pdu.c @@ -6152,12 +6152,12 @@ static noinline int smb2_read_pipe(struct ksmbd_work *work) memcpy(aux_payload_buf, rpc_resp->payload, rpc_resp->payload_sz); nbytes = rpc_resp->payload_sz; - kvfree(rpc_resp); err = ksmbd_iov_pin_rsp_read(work, (void *)rsp, offsetof(struct smb2_read_rsp, Buffer), aux_payload_buf, nbytes); if (err) goto out; + kvfree(rpc_resp); } else { err = ksmbd_iov_pin_rsp(work, (void *)rsp, offsetof(struct smb2_read_rsp, Buffer));