Received: by 2002:a25:23cc:0:0:0:0:0 with SMTP id j195csp1374005ybj; Thu, 7 May 2020 23:10:29 -0700 (PDT) X-Google-Smtp-Source: APiQypJgpiqCXA9YC2xrrVzOTjoiWftFKTngtCqYIhUA3YwwTs55/kMOPW6GAXGjGL3+6cieYk+7 X-Received: by 2002:a17:906:1292:: with SMTP id k18mr547093ejb.132.1588918229071; Thu, 07 May 2020 23:10:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1588918229; cv=none; d=google.com; s=arc-20160816; b=PPif/FbzKQGurJV7T/bNhAXzxQ4ZxdrE7WBu6FiU0Chogi70EEaJLZcY3hA7eCRoSU 6S21FMEWlS0qXVmBeGZzKS7LybVNmfxVQqqNx5E+BpJYZhMrN5O2BYAwo0flo8iAxotp DLwNS3YrQiIkL6SxazIJi5bHmUyfUDGhxf6etiRp5pZBT2ywLcSEY0Swv94ws2YG8qNj 72XzR3gILMIfh60hq/9JKWdA4bwvUNw/MzNy4O3T3InYATSXT3z8X37fi3NhaBEpYaAU /ef+P8ZY/8+EkOoBYMURAnbOD07InwKiEYO97NaV0Ay9IFvMohmlpe6pNVrzjKu9lYMP l04A== 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 :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject; bh=YqumPphF4FskRFtznLqhIjCt/XxdQaavdgez97tgddo=; b=IIU7Z4T2/CRMQefq92CuSbV6fXi4Qy+i7eqOyABWowY2C3SeA06j6UWKn3OcsGDe45 7tLlSydxt0JJIWGbP9q2KNh9PWzrkFb6JQejP79cWb6QKoNhvwd9pIctFygdpN6Fulfi Ib5cS1kRORw+t7Xeo54nFJf0XjPh26k5MYxI+rj6HVImH/MeKFh1XQ6WyxYAwIF2joVf YNehbjkTVmmXJ0+983zSv2kLXr5DUazGii6U/EsnrfOYFp+3/CEBHexByYWhAmpqJ82i /K5iRlekpNOojObmkChGUucib+iCCNKqxAnhidUB8dnqgYVnSVLP/J/oBE4+4yIxRlGv 7Njg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=virtuozzo.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id l11si365080eja.20.2020.05.07.23.10.05; Thu, 07 May 2020 23:10:29 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=virtuozzo.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726873AbgEHGIZ (ORCPT + 99 others); Fri, 8 May 2020 02:08:25 -0400 Received: from relay.sw.ru ([185.231.240.75]:51552 "EHLO relay.sw.ru" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726009AbgEHGIY (ORCPT ); Fri, 8 May 2020 02:08:24 -0400 Received: from vvs-ws.sw.ru ([172.16.24.21]) by relay.sw.ru with esmtp (Exim 4.92.3) (envelope-from ) id 1jWwAy-0002jG-Cj; Fri, 08 May 2020 09:08:00 +0300 Subject: Re: [PATCH] ipc/util.c: sysvipc_find_ipc() incorrectly updates position index To: Matthew Wilcox , Andrew Morton Cc: linux-kernel@vger.kernel.org, Waiman Long , Andreas Schwab References: <4921fe9b-9385-a2b4-1dc4-1099be6d2e39@virtuozzo.com> <20200507170242.6cbb88ae672deed67152e221@linux-foundation.org> <20200508033625.GO16070@bombadil.infradead.org> From: Vasily Averin Message-ID: Date: Fri, 8 May 2020 09:07:59 +0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.7.0 MIME-Version: 1.0 In-Reply-To: <20200508033625.GO16070@bombadil.infradead.org> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 5/8/20 6:36 AM, Matthew Wilcox wrote: > On Thu, May 07, 2020 at 05:02:42PM -0700, Andrew Morton wrote: >> Here's how I resolved things. Please check? >> >> static struct kern_ipc_perm *sysvipc_find_ipc(struct ipc_ids *ids, loff_t pos, >> loff_t *new_pos) >> { >> unsigned long index = pos; >> struct kern_ipc_perm *ipc; >> >> rcu_read_lock(); >> ipc = xa_find(&ids->ipcs, &index, ULONG_MAX, XA_PRESENT); >> if (ipc) >> ipc_lock_object(ipc); >> else >> rcu_read_unlock(); >> *new_pos = pos + 1; >> return ipc; >> } > > Surely that should be '*new_pos = index + 1'? Or did I misunderstand > the reasoning behind the other patch? I'm not sure however it looks like xa_find() can return index < pos xa_find in our case will call xas_find_marked() that have following description * If no marked entry is found and the array is smaller than @max, @xas is * set to the bounds state and xas->xa_index is set to the smallest index * not yet in the array. This allows @xas to be immediately passed to * xas_store(). Matthew, could you please clarify this question? Thank you, Vasily Averin