Received: by 2002:ac0:a582:0:0:0:0:0 with SMTP id m2-v6csp1350407imm; Tue, 2 Oct 2018 06:57:11 -0700 (PDT) X-Google-Smtp-Source: ACcGV61oSgtTE4tHkwXicpPtxcV/AfhLjYlO4kIgsBML0R33CdVTkhD/IOmpy1toOCW9uTZznZdW X-Received: by 2002:a17:902:8d82:: with SMTP id v2-v6mr17284643plo.9.1538488631395; Tue, 02 Oct 2018 06:57:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1538488631; cv=none; d=google.com; s=arc-20160816; b=gRg7zI9T7LySBxfdAxKQwMIUOXXAw5EXmEFCbtlDiD8Vc1f6Z0PefiuJfdBFIMKt94 sASkriFPcDUgI+j8YderYXS0umcHcW327k8c5+vKKj+BGKKyOFb2Vcxa4MQuINSmNtkT nqoylxSykayM84o4xLTi+CP1Xof6jkOaBJQ2ENStzKdkD9Icrd4MLEnPGRstwm+6hjdr hDLc+xPAiULAMe3xmcCV0yEucf7GXjPz7kHarVZE0YWP4zQkJV0kIIYpZrwjzfQwUrMd +W4wfSjTimHZGgZfU5wpfzYPaM1juuR/2cMd4D01MXBLmy3YaL3su42EDqPbP9k9q9DD SFFA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from; bh=L7Y6B1VMYndobDVOEeuWkxp7PeGYx0k/Tun5xv6rmj0=; b=SAEK+MlVq9wwdwKc5MtiE+SKhNV/ncoPdJQesoDwubIrwLmseMnmj8QA8TzMhbJBCA lObxWjJDx3WTdNJx2oxiKYbVaxfrpiAEt4hLodpJlB7twOkIDXEJykvPfzk8oBLUZhUn y0IdocviF40dDAW2Tg1RnQ0+kl/IfLxV3jyFchMd5svQuxfZ6k6PKnDL1BeZfWV31zma y3eEXqpXmC14vIL0FLqrbDEajXTRpkwyvIlYsiiemkYl5pwW1cwZz0k9vaqu66neNNWa 1VM2B9Zurh9JHzZ7wluL5s0u/w682gaDFW5mUEQh0Qi6ZLRNKNNq1RZH2l58aBH0LlCi xKxw== 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 d7-v6si15487139pll.162.2018.10.02.06.56.56; Tue, 02 Oct 2018 06:57:11 -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 S1731098AbeJBUO7 (ORCPT + 99 others); Tue, 2 Oct 2018 16:14:59 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:34192 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731049AbeJBUO4 (ORCPT ); Tue, 2 Oct 2018 16:14:56 -0400 Received: from localhost (24-104-73-23-ip-static.hfc.comcastbusiness.net [24.104.73.23]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 341E6C47; Tue, 2 Oct 2018 13:31:34 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, =?UTF-8?q?Stefan=20Br=C3=BCns?= , Jonathan Cameron , Akinobu Mita , Jonathan Cameron , Sasha Levin Subject: [PATCH 4.14 002/137] iio: adc: ina2xx: avoid kthread_stop() with stale task_struct Date: Tue, 2 Oct 2018 06:23:23 -0700 Message-Id: <20181002132458.591076701@linuxfoundation.org> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20181002132458.446916963@linuxfoundation.org> References: <20181002132458.446916963@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.14-stable review patch. If anyone has any objections, please let me know. ------------------ From: Akinobu Mita [ Upstream commit 7d6cd21d82bacab2d1786fe5e989e4815b75d9a3 ] When the buffer is enabled for ina2xx driver, a dedicated kthread is invoked to capture mesurement data. When the buffer is disabled, the kthread is stopped. However if the kthread gets register access errors, it immediately exits and when the malfunctional buffer is disabled, the stale task_struct pointer is accessed as there is no kthread to be stopped. A similar issue in the usbip driver is prevented by kthread_get_run and kthread_stop_put helpers by increasing usage count of the task_struct. This change applies the same solution. Cc: Stefan BrĂ¼ns Cc: Jonathan Cameron Signed-off-by: Akinobu Mita Fixes: c43a102e67db ("iio: ina2xx: add support for TI INA2xx Power Monitors") Signed-off-by: Jonathan Cameron Signed-off-by: Sasha Levin Signed-off-by: Greg Kroah-Hartman --- drivers/iio/adc/ina2xx-adc.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) --- a/drivers/iio/adc/ina2xx-adc.c +++ b/drivers/iio/adc/ina2xx-adc.c @@ -30,6 +30,7 @@ #include #include #include +#include #include #include @@ -701,6 +702,7 @@ static int ina2xx_buffer_enable(struct i { struct ina2xx_chip_info *chip = iio_priv(indio_dev); unsigned int sampling_us = SAMPLING_PERIOD(chip); + struct task_struct *task; dev_dbg(&indio_dev->dev, "Enabling buffer w/ scan_mask %02x, freq = %d, avg =%u\n", (unsigned int)(*indio_dev->active_scan_mask), @@ -710,11 +712,17 @@ static int ina2xx_buffer_enable(struct i dev_dbg(&indio_dev->dev, "Async readout mode: %d\n", chip->allow_async_readout); - chip->task = kthread_run(ina2xx_capture_thread, (void *)indio_dev, - "%s:%d-%uus", indio_dev->name, indio_dev->id, - sampling_us); + task = kthread_create(ina2xx_capture_thread, (void *)indio_dev, + "%s:%d-%uus", indio_dev->name, indio_dev->id, + sampling_us); + if (IS_ERR(task)) + return PTR_ERR(task); + + get_task_struct(task); + wake_up_process(task); + chip->task = task; - return PTR_ERR_OR_ZERO(chip->task); + return 0; } static int ina2xx_buffer_disable(struct iio_dev *indio_dev) @@ -723,6 +731,7 @@ static int ina2xx_buffer_disable(struct if (chip->task) { kthread_stop(chip->task); + put_task_struct(chip->task); chip->task = NULL; }