Received: by 10.223.185.116 with SMTP id b49csp512332wrg; Fri, 16 Feb 2018 02:45:42 -0800 (PST) X-Google-Smtp-Source: AH8x227gE3xLtt51N4cz8UOUC9s/K/BirmhvvkTG74AfVtyUOQgij6AxuTvzqsyQe+LbETLkK8bW X-Received: by 10.99.170.77 with SMTP id x13mr4825019pgo.393.1518777941952; Fri, 16 Feb 2018 02:45:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1518777941; cv=none; d=google.com; s=arc-20160816; b=WgfSAC1y3/+OL0QzOfCRZHt5NmfS+B4zMjIEULH59oRdGqGU6QlwuTLqEUSaV8EhHd fVg2yS/MNbgzydNnD20T27q8fHjQw1eGuTJg5Ihcw10YgXT/aczBPny0XJlaWo9kuGI6 c1UwznsaiesmAv6B1BXDIgN1JlDDcxZ8MWcAa4tCTv2sWr16VMTHZM4hrdaAVUA+SnbU waGGOZ7NYqCAhBXrFdiP0mF4NjYRLE/8BMc18B1CEl7i8fdVDvZ8vMq1k8+vwIVZtUA2 L4Mz2ARIrxcjuB1GmtUa1B/30GUxJszSDRc7FvMQVgXUGZsQIyA7nmFo5YCmlBJtf9kf Uxrw== 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=gn8mKJGFP1pNVzDC9xf/gHG2YEGQhraoeBqHJuk1GOU=; b=QnnPGTvQ+LSWgwZvcglXcdINj6gJbQheFpJQnlap+dqIhrjKibKlvKd0WhnskP+XzC mZDQnphR74jgydsMk9ul/PQhYgGpt1Ni0DKb3a1cIolbha+hhvT/lieXDjPuWFvvsPQq ajxS9Q0DKI/nUnz8XTOL83QOx+X4MJm7Jv8SiLfEAg9Xcxe+Tp6yJdUiPwGKVcb1YS3j Hm8GlbiPMJ9/BWMq+nrHzv3P+YRNtiwjG0T/GhqMD1snZQZFHaMlNENzttN4kh7WbomN xA5M3kvGpa+jnK85xnDVSNFkwnqiz7gSvil5MElHywdyzQeAe5WMIjBcrHcsszP1mvKG ogcQ== 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 y190si2799877pfy.87.2018.02.16.02.45.27; Fri, 16 Feb 2018 02:45:41 -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 S1427132AbeBORQM (ORCPT + 99 others); Thu, 15 Feb 2018 12:16:12 -0500 Received: from mail.linuxfoundation.org ([140.211.169.12]:58634 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1422926AbeBOPgk (ORCPT ); Thu, 15 Feb 2018 10:36:40 -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 22972D96; Thu, 15 Feb 2018 15:36:33 +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.14 153/195] kernel/async.c: revert "async: simplify lowest_in_progress()" Date: Thu, 15 Feb 2018 16:17:24 +0100 Message-Id: <20180215151713.534400158@linuxfoundation.org> X-Mailer: git-send-email 2.16.1 In-Reply-To: <20180215151705.738773577@linuxfoundation.org> References: <20180215151705.738773577@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.14-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;