Received: by 2002:ac0:a591:0:0:0:0:0 with SMTP id m17-v6csp1426800imm; Thu, 5 Jul 2018 23:14:14 -0700 (PDT) X-Google-Smtp-Source: AAOMgpcfqm059JtRWsVCPhmUN1PwlNWMeXvoquY/Sl3yyl8kGv0ZB6cKNiLDBQFU1kT6kzS5NeVI X-Received: by 2002:a63:1546:: with SMTP id 6-v6mr8321478pgv.271.1530857654789; Thu, 05 Jul 2018 23:14:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1530857654; cv=none; d=google.com; s=arc-20160816; b=bbWFtXyXL5n0OCtsKzpB1VTuQr59sDF7kBjNfOf3O3d4hj6YC0pJHziJ7Bsa7syLbn 9t4swtu3i8SRW/PKt7u8MYWTszS4ft6sZ6tbAHZIQVrGCU/h5vAUJoyIhTl2/XpwQXbm 9rGdFmfyV8i7nI6jWSfOkcTpQqvLiJhm8TiDGtSfcMwQdPOIjwrMTSr+X6K588oN0b5D cW194OtFqLRKItYMb6rTs7Jb3MlvACt4ovb1xsJG3zI4ZWBEVYUeImBkwP3qn7nbVKYt Uz9Mp72mDOkPfFX82sinPJZ1jUdidwWFfY8EStVCPeSLzjARwrFWEcNTq4IJM8ZGnTTR VnpA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=wQnA4Y8mYCSBPAPZslRUOhtfAx+/Pf9c23JH5BM8HZY=; b=hGz/6CovgA9qGUqc8YV46cy5T3/zQaY1S4XgDvTS7b8sL7oi5X45NzeADP5DVyDm0R 0l7wPtq+UOeCIckAbLzEvhEA63EBxZqwhSFXGrb9yl7qvRQtDWYsjge4IDJnGpt5SqIu e6npUgqfPUpo8Rj0c4rc38mEQVp5Xi8QPKRkvRmWgzQcDxp6ZTajlLYm7xcc3OtPKb0T P3aZkeKotcOz4RulFp9lgVHVaN0ICtqqbvlVdhY2G0U/2p63/k/6fCVBmupzjrv2mWiX 65HS3zBpQo2gXZ5Gq2Ly31NxHebfYyg3RZ4CdusqdrCWzOg0M2NCSSHmtzyhkooAFTDM SFHw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id t85-v6si8060092pfj.231.2018.07.05.23.14.00; Thu, 05 Jul 2018 23:14:14 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932857AbeGFFrg (ORCPT + 99 others); Fri, 6 Jul 2018 01:47:36 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:58570 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932824AbeGFFrd (ORCPT ); Fri, 6 Jul 2018 01:47:33 -0400 Received: from localhost (D57D388D.static.ziggozakelijk.nl [213.125.56.141]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id EAC2186A; Fri, 6 Jul 2018 05:47:32 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Heikki Krogerus , Guenter Roeck , Jun Li , Peter Chen Subject: [PATCH 4.17 05/46] usb: typec: tcpm: fix logbuffer index is wrong if _tcpm_log is re-entered Date: Fri, 6 Jul 2018 07:46:26 +0200 Message-Id: <20180706054524.870420292@linuxfoundation.org> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180706054524.595521988@linuxfoundation.org> References: <20180706054524.595521988@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.17-stable review patch. If anyone has any objections, please let me know. ------------------ From: Peter Chen commit d5a4f93511b7000183c0d528739b824752139f79 upstream. The port->logbuffer_head may be wrong if the two processes enters _tcpm_log at the mostly same time. The 2nd process enters _tcpm_log before the 1st process update the index, then the 2nd process will not allocate logbuffer, when the 2nd process tries to use log buffer, the index has already updated by the 1st process, so it will get NULL pointer for updated logbuffer, the error message like below: tcpci 0-0050: Log buffer index 6 is NULL Cc: Heikki Krogerus Cc: Guenter Roeck Cc: Jun Li Signed-off-by: Peter Chen Reviewed-by: Heikki Krogerus Cc: stable Reviewed-by: Guenter Roeck Signed-off-by: Greg Kroah-Hartman Signed-off-by: Greg Kroah-Hartman --- drivers/usb/typec/tcpm.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) --- a/drivers/usb/typec/tcpm.c +++ b/drivers/usb/typec/tcpm.c @@ -388,17 +388,18 @@ static void _tcpm_log(struct tcpm_port * u64 ts_nsec = local_clock(); unsigned long rem_nsec; + mutex_lock(&port->logbuffer_lock); if (!port->logbuffer[port->logbuffer_head]) { port->logbuffer[port->logbuffer_head] = kzalloc(LOG_BUFFER_ENTRY_SIZE, GFP_KERNEL); - if (!port->logbuffer[port->logbuffer_head]) + if (!port->logbuffer[port->logbuffer_head]) { + mutex_unlock(&port->logbuffer_lock); return; + } } vsnprintf(tmpbuffer, sizeof(tmpbuffer), fmt, args); - mutex_lock(&port->logbuffer_lock); - if (tcpm_log_full(port)) { port->logbuffer_head = max(port->logbuffer_head - 1, 0); strcpy(tmpbuffer, "overflow");