Received: by 2002:a05:6602:18e:0:0:0:0 with SMTP id m14csp2104254ioo; Mon, 23 May 2022 10:08:59 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwUlb4abVGfB7C7WClWK+TMa5hX/cajzEEjcotpgG6w/LX8pZybQz+iLWsFyubPhnypr+uX X-Received: by 2002:a17:90b:3909:b0:1e0:49d7:ca85 with SMTP id ob9-20020a17090b390900b001e049d7ca85mr7085103pjb.191.1653325739608; Mon, 23 May 2022 10:08:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1653325739; cv=none; d=google.com; s=arc-20160816; b=lvplrl6b+1fndN7MtKi7V8u/VYefyTwfBstqmtLLMX5HKIHtvVClGX+YmhVD+y8RUT 3KC1sKblNcvUwOsrnTw7jjH+shOJD/6AjCHT/Rsm/ykThT97lw7905hJwS/CCzk0hCI1 2WhkgErCFV4dqQ8mqTqy1BEcoBz+2YpwWzs/HHBr7fikJIVRpRDqHotzJanhpXfg4cmk 0C09jFWF9WqoAM9T316qmnzw0W9TDCW9+H8crt6GtbLmZC6w8NYXhGMNc1guA4vnjKJ7 6r2EZztxqTAe5a58BKBjgTOn3gHDKCNrXKynQ6PHOslsZu/aV2/3Kiuwa8IVccHGbmig dnlw== 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=t1sk2xrYJffTUytYzn/hGUFfz8sjg0b9qVFANZ4KNLw=; b=QkLCMvgGO7mGMm2E/rL8JkMyYLceFF63LLlbAwndl/4l7iOWpnvZX2/3CsP43CBu+f Z6D/XFcPkT2Y+sFaSodict5yBJibsWwTXIoB69u+uvz2gKKQxkDD2j2PCkatOSiuU2tt fUeyGYHuHUc8ZwPrR6pflT6nKsmfeLWbuOADIpfxwIxa274H5zEB9WVdVKu9Zcl/yQK2 Ax/2vC8czEHkVdNDjFWZ75kWHewEPbqWwxVVdqJMoUYh32Rs4B71w6zIwtU1FdQ0sTg1 SAbTP0hR9odxrjc3zA3bQOnwFl/ODanBGB5Q1xNJCW8Po++1Np9jE2IeWAIpaLm7c2dy /aZA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=cPT+dJne; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1: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 lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id h3-20020a170902f54300b0015d2c7ccec4si11725112plf.310.2022.05.23.10.08.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 May 2022 10:08:59 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=cPT+dJne; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1: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: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 619B06C0D9; Mon, 23 May 2022 10:08:47 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239565AbiEWRID (ORCPT + 99 others); Mon, 23 May 2022 13:08:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59506 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239533AbiEWRHg (ORCPT ); Mon, 23 May 2022 13:07:36 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DF6906AA4F; Mon, 23 May 2022 10:07:09 -0700 (PDT) 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 ams.source.kernel.org (Postfix) with ESMTPS id 3328AB811F0; Mon, 23 May 2022 17:07:08 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8FB22C385A9; Mon, 23 May 2022 17:07:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1653325627; bh=ALhDDiyUuIA/5zUv3h6o0CEG467Pvbsx6fVAiLEImbI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=cPT+dJneOTk93O3ba+lpMkHwT/nvWSGYYQtIZpVcozieUjaYJFMUibehXShlmKu9s 1K7r2zoNB30J1hDa+LkrM05Lbf8VY8QbmC28nbAGDx30nJbv0Vwb10jwuW9jI/a3LD DXFsFiLjfj4K81EBhrHRL7yLxpmX2Pq0Ut6W3k6M= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Minh Yuan , Linus Torvalds , Denis Efremov , Willy Tarreau , Linus Torvalds Subject: [PATCH 5.4 01/68] floppy: use a statically allocated error counter Date: Mon, 23 May 2022 19:04:28 +0200 Message-Id: <20220523165802.768402454@linuxfoundation.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220523165802.500642349@linuxfoundation.org> References: <20220523165802.500642349@linuxfoundation.org> User-Agent: quilt/0.66 X-stable: review X-Patchwork-Hint: ignore MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable 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-kernel@vger.kernel.org From: Willy Tarreau commit f71f01394f742fc4558b3f9f4c7ef4c4cf3b07c8 upstream. Interrupt handler bad_flp_intr() may cause a UAF on the recently freed request just to increment the error count. There's no point keeping that one in the request anyway, and since the interrupt handler uses a static pointer to the error which cannot be kept in sync with the pending request, better make it use a static error counter that's reset for each new request. This reset now happens when entering redo_fd_request() for a new request via set_next_request(). One initial concern about a single error counter was that errors on one floppy drive could be reported on another one, but this problem is not real given that the driver uses a single drive at a time, as that PC-compatible controllers also have this limitation by using shared signals. As such the error count is always for the "current" drive. Reported-by: Minh Yuan Suggested-by: Linus Torvalds Tested-by: Denis Efremov Signed-off-by: Willy Tarreau Signed-off-by: Linus Torvalds Signed-off-by: Denis Efremov Signed-off-by: Greg Kroah-Hartman --- drivers/block/floppy.c | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) --- a/drivers/block/floppy.c +++ b/drivers/block/floppy.c @@ -521,8 +521,8 @@ static unsigned long fdc_busy; static DECLARE_WAIT_QUEUE_HEAD(fdc_wait); static DECLARE_WAIT_QUEUE_HEAD(command_done); -/* Errors during formatting are counted here. */ -static int format_errors; +/* errors encountered on the current (or last) request */ +static int floppy_errors; /* Format request descriptor. */ static struct format_descr format_req; @@ -542,7 +542,6 @@ static struct format_descr format_req; static char *floppy_track_buffer; static int max_buffer_sectors; -static int *errors; typedef void (*done_f)(int); static const struct cont_t { void (*interrupt)(void); @@ -1435,7 +1434,7 @@ static int interpret_errors(void) if (DP->flags & FTD_MSG) DPRINT("Over/Underrun - retrying\n"); bad = 0; - } else if (*errors >= DP->max_errors.reporting) { + } else if (floppy_errors >= DP->max_errors.reporting) { print_errors(); } if (ST2 & ST2_WC || ST2 & ST2_BC) @@ -2055,7 +2054,7 @@ static void bad_flp_intr(void) if (!next_valid_format()) return; } - err_count = ++(*errors); + err_count = ++floppy_errors; INFBOUND(DRWE->badness, err_count); if (err_count > DP->max_errors.abort) cont->done(0); @@ -2200,9 +2199,8 @@ static int do_format(int drive, struct f return -EINVAL; } format_req = *tmp_format_req; - format_errors = 0; cont = &format_cont; - errors = &format_errors; + floppy_errors = 0; ret = wait_til_done(redo_format, true); if (ret == -EINTR) return -EINTR; @@ -2677,7 +2675,7 @@ static int make_raw_rw_request(void) */ if (!direct || (indirect * 2 > direct * 3 && - *errors < DP->max_errors.read_track && + floppy_errors < DP->max_errors.read_track && ((!probing || (DP->read_track & (1 << DRS->probed_format)))))) { max_size = blk_rq_sectors(current_req); @@ -2801,10 +2799,11 @@ static int set_next_request(void) current_req = list_first_entry_or_null(&floppy_reqs, struct request, queuelist); if (current_req) { - current_req->error_count = 0; + floppy_errors = 0; list_del_init(¤t_req->queuelist); + return 1; } - return current_req != NULL; + return 0; } static void redo_fd_request(void) @@ -2860,7 +2859,6 @@ do_request: _floppy = floppy_type + DP->autodetect[DRS->probed_format]; } else probing = 0; - errors = &(current_req->error_count); tmp = make_raw_rw_request(); if (tmp < 2) { request_done(tmp);