Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp3635027pxb; Mon, 24 Jan 2022 14:03:49 -0800 (PST) X-Google-Smtp-Source: ABdhPJxNK+nzToZF5bwrLvxSP9RYdLkeuKEQ4XUgp3UD+7ZOSOkqVlrvyd6H2j0S6kETq++trxWT X-Received: by 2002:a17:90b:181:: with SMTP id t1mr312521pjs.240.1643061829359; Mon, 24 Jan 2022 14:03:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643061829; cv=none; d=google.com; s=arc-20160816; b=H7kosgc5kZ08AuSDFX5KbC+rA/hAQarfNdIL7x+AryY3KvRWQOlgr8NOkW37TuYs2V azkKjerwCdL3DT/g5R5aSvoRdQZUmxRcLdJNf35Ui+FSsuJEsesNFSxgjjzXdhlHEDII Ctcn26OsY17EURx+4T2TvnkxixLqBg2M1st+BQ0DuxfDrAFt+yvKylnSCCN+ICCOWXhO mQLo+dcNDaF5+GBclS4IyGzcn8/iOuHnzO6xaO6C31Gv5ZsAiHAVJsEno2tyHYM5oWxY vf52KPdiGH3X1Ikrui5nhBfyT3lZW0a5EY3VPJ5AVjNfsDiP4SGkjPVS/4bXlfSpZVg2 kcqA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=GdFPOvfVESDvpB1GlhcKk0aUhN0d13qaWq7ONMqIePs=; b=Gkg6qVWaz8YdAqrjyb/QyDJ/bXD2pU7hCFqLQ8/75AVqvsU/9qr3cVkbS7AhNsYdl9 x3dJNsKLqnz8kYx4D2Q/+8hv9HfcGBjp1jr7DLqK7jTEvgwJL5DvwLdOo496Gc5Pnfl0 3WRDiujofQKw8FyX0GnTnaKeEMIw0BQIBGAxx7Tcnu4Qmhld6ik9+ua7FnWfa9/XYNJS g5R1MfVr0hVubNVfW0ha3V59r63chYfznSnC3uRRH35TkMbVKQ0DdGae/SPMN/8dwwv+ wjXOm9/R41pLYjaAkzK5D8f3zljoIX3Cq7ZJn1J0sBBwynwv6HhTl80L20/VwsXZWc8v rsNQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="XLMt/JrT"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id r25si15154135pge.741.2022.01.24.14.03.37; Mon, 24 Jan 2022 14:03:49 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="XLMt/JrT"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1575039AbiAXVu5 (ORCPT + 99 others); Mon, 24 Jan 2022 16:50:57 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49392 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1449137AbiAXVO6 (ORCPT ); Mon, 24 Jan 2022 16:14:58 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 73E2BC06E022; Mon, 24 Jan 2022 12:11:33 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 125486090A; Mon, 24 Jan 2022 20:11:33 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D34F1C340E5; Mon, 24 Jan 2022 20:11:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1643055092; bh=cMe5TVEH+85mLz30fZNS5w7QP6RVRhHXa4IA51gWmQE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=XLMt/JrTaiPtCPvu3goLO4Nllh0sSXkAxZ91YXSIb3KlLzCKZEvj3G6ZaZRAR2+Zn EKSzPy0JUqYLFKd2IKQHcSwI63azY+zaxTw1xa5+zjx71gzwyENi8sI5Ltjnj0PG+C KKnsImEw+2LL7VN15tX0iqvmYjha/7qzcH6L4Dnk= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Namjae Jeon , Steve French Subject: [PATCH 5.15 037/846] ksmbd: move credit charge deduction under processing request Date: Mon, 24 Jan 2022 19:32:34 +0100 Message-Id: <20220124184102.220566073@linuxfoundation.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220124184100.867127425@linuxfoundation.org> References: <20220124184100.867127425@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Namjae Jeon commit 914d7e5709ac59ded70bea7956d408fe2acd7c3c upstream. Moves the credit charge deduction from total_credits under the processing a request. When repeating smb2 lock request and other command request, there will be a problem that ->total_credits does not decrease. Signed-off-by: Namjae Jeon Signed-off-by: Steve French Signed-off-by: Greg Kroah-Hartman --- fs/ksmbd/smb2misc.c | 7 ++----- fs/ksmbd/smb2pdu.c | 16 ++++++++++------ 2 files changed, 12 insertions(+), 11 deletions(-) --- a/fs/ksmbd/smb2misc.c +++ b/fs/ksmbd/smb2misc.c @@ -290,7 +290,7 @@ static int smb2_validate_credit_charge(s unsigned int req_len = 0, expect_resp_len = 0, calc_credit_num, max_len; unsigned short credit_charge = le16_to_cpu(hdr->CreditCharge); void *__hdr = hdr; - int ret; + int ret = 0; switch (hdr->Command) { case SMB2_QUERY_INFO: @@ -333,10 +333,7 @@ static int smb2_validate_credit_charge(s } spin_lock(&conn->credits_lock); - if (credit_charge <= conn->total_credits) { - conn->total_credits -= credit_charge; - ret = 0; - } else { + if (credit_charge > conn->total_credits) { ksmbd_debug(SMB, "Insufficient credits granted, given: %u, granted: %u\n", credit_charge, conn->total_credits); ret = 1; --- a/fs/ksmbd/smb2pdu.c +++ b/fs/ksmbd/smb2pdu.c @@ -301,9 +301,8 @@ int smb2_set_rsp_credits(struct ksmbd_wo struct smb2_hdr *req_hdr = ksmbd_req_buf_next(work); struct smb2_hdr *hdr = ksmbd_resp_buf_next(work); struct ksmbd_conn *conn = work->conn; - unsigned short credits_requested; + unsigned short credits_requested, aux_max; unsigned short credit_charge, credits_granted = 0; - unsigned short aux_max, aux_credits; if (work->send_no_response) return 0; @@ -318,6 +317,13 @@ int smb2_set_rsp_credits(struct ksmbd_wo credit_charge = max_t(unsigned short, le16_to_cpu(req_hdr->CreditCharge), 1); + if (credit_charge > conn->total_credits) { + ksmbd_debug(SMB, "Insufficient credits granted, given: %u, granted: %u\n", + credit_charge, conn->total_credits); + return -EINVAL; + } + + conn->total_credits -= credit_charge; credits_requested = max_t(unsigned short, le16_to_cpu(req_hdr->CreditRequest), 1); @@ -327,13 +333,11 @@ int smb2_set_rsp_credits(struct ksmbd_wo * TODO: Need to adjuct CreditRequest value according to * current cpu load */ - aux_credits = credits_requested - 1; if (hdr->Command == SMB2_NEGOTIATE) - aux_max = 0; + aux_max = 1; else aux_max = conn->vals->max_credits - credit_charge; - aux_credits = min_t(unsigned short, aux_credits, aux_max); - credits_granted = credit_charge + aux_credits; + credits_granted = min_t(unsigned short, credits_requested, aux_max); if (conn->vals->max_credits - conn->total_credits < credits_granted) credits_granted = conn->vals->max_credits -