Received: by 10.223.185.116 with SMTP id b49csp2557688wrg; Thu, 15 Feb 2018 13:36:24 -0800 (PST) X-Google-Smtp-Source: AH8x2258QqJOr9Z6cpEEMi0EKQgRuc9Cq7/jbNbg1PL6OedZvgEmX+21qlMQGBGQsxe5o5pMMwmw X-Received: by 2002:a17:902:1a2:: with SMTP id b31-v6mr3616601plb.28.1518730584363; Thu, 15 Feb 2018 13:36:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1518730584; cv=none; d=google.com; s=arc-20160816; b=UBfIO/4oNfiymC40OzPz4XQJ+KOdQxOwhT/hDnNlPIrdJ3RY6n8WqKzND8ZDKj+CTI As8WhM1HQTPnUwtQ4dhUTOCrV/++xizv3yCEuBk91iEGTwJrtF944WRrWP9Ojhn3NraS A5bNOURig/rKUvYK22I9mZ540o0mfl5pYP/TlXh0R8rcEmguLp5DBFj3/fGHMjWvrqXo W6A+QBfwKVimXkHkrydp579Pa3v8ah0yG/+FPIywShiVXY4EqDg1WjsH3XLL/o3mWdrL Bi7lXdmmRN2cfeX8uJl6RmnvRl1JmeU1hibJEzZquhozZ3DLEM6k+ZuGdPf/rvMp73GL BFjw== 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=OTHVWvCGfinJ0xkhfmKeObnqZlyWMfZQLVfhPICK9S8=; b=dYfxhwFTnroTPTHvKrRZKWe9Vw1V04DR0hyEdKFhm5/3y2SLXfY+SAxkSjVewnCyt8 X/dtrfwHqI/geiwgG9xCF39vQ48dCMs0wQq26vOicnPX25ZQn4MXBmN/9QQ4HuFBbO3M Q5mz9Pef4NI3AkT83WDGrC/ocE0HtU24ztsXTvYqDvEvTBWZkaUlxnkfT1FPvXNAYyFq c80CinfRgPo0d3DxijzHj+OKCh4R0XvzSt2AztqcPgqJ3dUJ4IF97jqZqbwBT7GwLRjw OxSVRScTV5MoRHTfmxmr+Lr/baMVOyaT4ieuUA5PRbgRVh3vz3xNCInK1eJY28AOlAeL PdyA== 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 o6-v6si357546pls.35.2018.02.15.13.36.09; Thu, 15 Feb 2018 13:36:24 -0800 (PST) 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 S1164067AbeBOP3h (ORCPT + 99 others); Thu, 15 Feb 2018 10:29:37 -0500 Received: from mail.linuxfoundation.org ([140.211.169.12]:54474 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1164055AbeBOP3e (ORCPT ); Thu, 15 Feb 2018 10:29:34 -0500 Received: from localhost (LFbn-1-12258-90.w90-92.abo.wanadoo.fr [90.92.71.90]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 143A610F0; Thu, 15 Feb 2018 15:29:32 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Rasmus Villemoes , Tejun Heo , Arjan van de Ven , Adam Wallis , Lai Jiangshan , Andrew Morton , Linus Torvalds Subject: [PATCH 4.9 62/88] kernel/async.c: revert "async: simplify lowest_in_progress()" Date: Thu, 15 Feb 2018 16:17:29 +0100 Message-Id: <20180215151231.220913443@linuxfoundation.org> X-Mailer: git-send-email 2.16.1 In-Reply-To: <20180215151222.437136975@linuxfoundation.org> References: <20180215151222.437136975@linuxfoundation.org> User-Agent: quilt/0.65 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.9-stable review patch. If anyone has any objections, please let me know. ------------------ From: Rasmus Villemoes commit 4f7e988e63e336827f4150de48163bed05d653bd upstream. This reverts commit 92266d6ef60c ("async: simplify lowest_in_progress()") which was simply wrong: In the case where domain is NULL, we now use the wrong offsetof() in the list_first_entry macro, so we don't actually fetch the ->cookie value, but rather the eight bytes located sizeof(struct list_head) further into the struct async_entry. On 64 bit, that's the data member, while on 32 bit, that's a u64 built from func and data in some order. I think the bug happens to be harmless in practice: It obviously only affects callers which pass a NULL domain, and AFAICT the only such caller is async_synchronize_full() -> async_synchronize_full_domain(NULL) -> async_synchronize_cookie_domain(ASYNC_COOKIE_MAX, NULL) and the ASYNC_COOKIE_MAX means that in practice we end up waiting for the async_global_pending list to be empty - but it would break if somebody happened to pass (void*)-1 as the data element to async_schedule, and of course also if somebody ever does a async_synchronize_cookie_domain(, NULL) with a "finite" cookie value. Maybe the "harmless in practice" means this isn't -stable material. But I'm not completely confident my quick git grep'ing is enough, and there might be affected code in one of the earlier kernels that has since been removed, so I'll leave the decision to the stable guys. Link: http://lkml.kernel.org/r/20171128104938.3921-1-linux@rasmusvillemoes.dk Fixes: 92266d6ef60c "async: simplify lowest_in_progress()" Signed-off-by: Rasmus Villemoes Acked-by: Tejun Heo Cc: Arjan van de Ven Cc: Adam Wallis Cc: Lai Jiangshan Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds Signed-off-by: Greg Kroah-Hartman --- kernel/async.c | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) --- a/kernel/async.c +++ b/kernel/async.c @@ -84,20 +84,24 @@ static atomic_t entry_count; static async_cookie_t lowest_in_progress(struct async_domain *domain) { - struct list_head *pending; + struct async_entry *first = NULL; async_cookie_t ret = ASYNC_COOKIE_MAX; unsigned long flags; spin_lock_irqsave(&async_lock, flags); - if (domain) - pending = &domain->pending; - else - pending = &async_global_pending; + if (domain) { + if (!list_empty(&domain->pending)) + first = list_first_entry(&domain->pending, + struct async_entry, domain_list); + } else { + if (!list_empty(&async_global_pending)) + first = list_first_entry(&async_global_pending, + struct async_entry, global_list); + } - if (!list_empty(pending)) - ret = list_first_entry(pending, struct async_entry, - domain_list)->cookie; + if (first) + ret = first->cookie; spin_unlock_irqrestore(&async_lock, flags); return ret;