Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D9788C433EF for ; Sun, 10 Oct 2021 15:18:48 +0000 (UTC) Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 3D89D60F38 for ; Sun, 10 Oct 2021 15:18:46 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 3D89D60F38 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=suse.de Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=alsa-project.org Received: from alsa1.perex.cz (alsa1.perex.cz [207.180.221.201]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by alsa0.perex.cz (Postfix) with ESMTPS id B20B9166E; Sun, 10 Oct 2021 17:17:54 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz B20B9166E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1633879124; bh=S/gC/DokagQOPSSvjbwE2TUJ45znjj8qmAKjOD9ts60=; h=Date:From:To:Subject:In-Reply-To:References:Cc:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=OPHYwjdaQMpL5QXCWYnM/ZkcRZIBT86MMzpZybg0U9LYL07lAbK3Qd78JmZ0I07Xk Q6rCB9AfiTDcq6RBEOt2ekSrZ0g0/EgJLNy/hKm3ap77u1Z2hDUC7ZhMaBTqugKAWS IpacgFOv/KLW0OE8LOx06lCMh9QRC/uxs2gbpyKw= Received: from alsa1.perex.cz (localhost.localdomain [127.0.0.1]) by alsa1.perex.cz (Postfix) with ESMTP id 3B330F801D5; Sun, 10 Oct 2021 17:17:54 +0200 (CEST) Received: by alsa1.perex.cz (Postfix, from userid 50401) id A897AF801F7; Sun, 10 Oct 2021 17:17:52 +0200 (CEST) Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by alsa1.perex.cz (Postfix) with ESMTPS id D2FC3F800F0 for ; Sun, 10 Oct 2021 17:17:45 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz D2FC3F800F0 Authentication-Results: alsa1.perex.cz; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="NU4nsiub"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="+d+kcLHp" Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out1.suse.de (Postfix) with ESMTP id D5C7921EF4; Sun, 10 Oct 2021 15:17:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1633879059; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=MQ/E2z8sQbYOhwnJ0Q3n0n0vwGNg1GKGwURyzAnc16Y=; b=NU4nsiubEepERxZIFjH/WFh1vJa8fRg57vCFYeig7FMkz+nP6VBqBa97mJqFd6Ge91qoT9 z88TRFP8xcuvutDb4JlsmN9a3FrJvYchJKCKm7QGL9Tq2gHMVyzolP4B5IEw16ZJFzH1qo ZFW+hUKZY6Lpr9j1tQ3Te/QFW+eAFqI= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1633879059; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=MQ/E2z8sQbYOhwnJ0Q3n0n0vwGNg1GKGwURyzAnc16Y=; b=+d+kcLHpAwjKxR3OwwnpnEK/3CJ2/ncCoSApixuPY8zSc6SocRbj1aT+d4eNRZiOqufHEd QGHUFMckYBiGjeAQ== Received: from alsa1.suse.de (alsa1.suse.de [10.160.4.42]) by relay2.suse.de (Postfix) with ESMTP id 9FBDEA3B81; Sun, 10 Oct 2021 15:17:39 +0000 (UTC) Date: Sun, 10 Oct 2021 17:17:39 +0200 Message-ID: From: Takashi Iwai To: Arnd Bergmann Subject: Re: [PATCH] ALSA: pcm: Workaround for a wrong offset in SYNC_PTR compat ioctl In-Reply-To: References: <20211010075546.23220-1-tiwai@suse.de> User-Agent: Wanderlust/2.15.9 (Almost Unreal) SEMI/1.14.6 (Maruoka) FLIM/1.14.9 (=?UTF-8?B?R29qxY0=?=) APEL/10.8 Emacs/25.3 (x86_64-suse-linux-gnu) MULE/6.0 (HANACHIRUSATO) MIME-Version: 1.0 (generated by SEMI 1.14.6 - "Maruoka") Content-Type: text/plain; charset=US-ASCII Cc: ALSA Development Mailing List , Rich Felker , Michael Forney X-BeenThere: alsa-devel@alsa-project.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: "Alsa-devel mailing list for ALSA developers - http://www.alsa-project.org" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: alsa-devel-bounces@alsa-project.org Sender: "Alsa-devel" On Sun, 10 Oct 2021 12:10:53 +0200, Arnd Bergmann wrote: > > On Sun, Oct 10, 2021 at 9:55 AM Takashi Iwai wrote: > > > > Michael Forney reported an incorrect padding type that was defined in > > the commit 80fe7430c708 ("ALSA: add new 32-bit layout for > > snd_pcm_mmap_status/control") for PCM control mmap data. > > His analysis is correct, and this caused the misplacements of PCM > > control data on 32bit arch and 32bit compat mode. > > > > The bug is that the __pad2 definition in __snd_pcm_mmap_control64 > > struct was wrongly with __pad_before_uframe, which should have been > > __pad_after_uframe instead. This struct is used in SYNC_PTR ioctl and > > control mmap. Basically this bug leads to two problems: > > > > - The offset of avail_min field becomes wrong, it's placed right after > > appl_ptr without padding on little-endian > > > > - When appl_ptr and avail_min are read as 64bit values in kernel side, > > the values become either zero or corrupted (mixed up) > > > > One good news is that, because both user-space and kernel > > misunderstand the wrong offset, at least, 32bit application running on > > 32bit kernel works as is. Also, 64bit applications are unaffected > > because the padding size is zero. The remaining problem is the 32bit > > compat mode; as mentioned in the above, avail_min is placed right > > after appl_ptr on little-endian archs, 64bit kernel reads bogus values > > for appl_ptr updates, which may lead to streaming bugs like jumping, > > XRUN or whatever unexpected. > > (However, we haven't heard any serious bug reports due to this over > > years, so practically seen, it's fairly safe to assume that the impact > > by this bug is limited.) > > > > Ideally speaking, we should correct the wrong mmap status control > > definition. But this would cause again incompatibility with the > > existing binaries, and fixing it (e.g. by renumbering ioctls) would be > > really messy. > > > > So, as of this patch, we only correct the behavior of 32bit compat > > mode and keep the rest as is. Namely, the SYNC_PTR ioctl is now > > handled differently in compat mode to read/write the 32bit values at > > the right offsets. The control mmap of 32bit apps on 64bit kernels > > has been already disabled (which is likely rather an overlook, but > > this worked fine at this time :), so covering SYNC_PTR ioctl should > > suffice as a fallback. > > > > Fixes: 80fe7430c708 ("ALSA: add new 32-bit layout for snd_pcm_mmap_status/control") > > Reported-by: Michael Forney > > Cc: > > Cc: Arnd Bergmann > > Cc: Rich Felker > > Link: https://lore.kernel.org/r/29QBMJU8DE71E.2YZSH8IHT5HMH@mforney.org > > Signed-off-by: Takashi Iwai > > Reviewed-by: Arnd Bergmann > > This does look like it's the best way we can get out of the mess we're > in for the kernel interface. > > Do you have any ideas for how to test this properly to ensure that > there are no further problems in these ioctls? Is there a testsuite > for ALSA that can be run on a musl-enabled distro in both native > and compat mode to exercise the ioctl and mmap interfaces? There is no known test program, and it's what I planned to check in the next week before merging :) thanks, Takashi