Bug 240992

Summary: linprocfs: /proc/[pid]/maps returns rounded file (?) size in the offset column
Product: Base System Reporter: Alex S <iwtcex>
Component: kernAssignee: Mark Johnston <markj>
Status: Closed FIXED    
Severity: Affects Only Me CC: markj
Priority: --- Keywords: patch
Version: 12.0-RELEASE   
Hardware: Any   
OS: Any   
Attachments:
Description Flags
proposed patch none

Description Alex S 2019-10-02 01:37:11 UTC
It should return an actual file offset or 0 if that is not applicable.
Comment 1 Alex S 2020-01-05 06:07:06 UTC
I've got a suspicion, based on https://forums.freebsd.org/threads/steamuxulation-redux.72140/page-4#post-448999, this might be relevant for Valve Anti-Cheat used by several popular Steam games.
Comment 2 Mark Johnston freebsd_committer freebsd_triage 2020-01-05 21:44:56 UTC
Created attachment 210472 [details]
proposed patch

Indeed, this column is supposed to be the mapping offset and linprocfs is just returning the object size.  The attached patch should fix it.  It also fixes a secondary bug which causes us to potentially print the previous entry's "offset" for an entry with no backing object.
Comment 3 Mark Johnston freebsd_committer freebsd_triage 2020-01-05 21:59:39 UTC
I guess this is not quite right when the mapping is COW, the entry's offset will give the offset into the top-level anonymous shadow object.  We need to sum the offsets along the object chain, assuming that Linux provides the same info.
Comment 4 Mark Johnston freebsd_committer freebsd_triage 2020-01-06 22:53:24 UTC
https://reviews.freebsd.org/D23062
Comment 5 commit-hook freebsd_committer freebsd_triage 2020-01-08 16:57:15 UTC
A commit references this bug:

Author: markj
Date: Wed Jan  8 16:57:08 UTC 2020
New revision: 356494
URL: https://svnweb.freebsd.org/changeset/base/356494

Log:
  linprocfs: Fix some bugs in the maps file implementation.

  - Export the offset into the backing object, not the object size.
  - Fix a bug where we would print the previous entry's "offset" when a
    map_entry has no object.
  - Try to identify shared mappings.  Linux prints "s" when the mapping
    "may be shared".  This attempt is not perfect, for example, we print
    "p" for anonymous memory that may be shared via
    minherit(INHERIT_SHARE).

  PR:		240992
  Reviewed by:	kib
  MFC after:	1 week
  MFC note:	no OBJ_ANON in stable/12
  Differential Revision:	https://reviews.freebsd.org/D23062

Changes:
  head/sys/compat/linprocfs/linprocfs.c
Comment 6 Alex S 2020-01-08 19:24:13 UTC
(In reply to Alex S from comment #1)

> I've got a suspicion,
> based on https://forums.freebsd.org/threads/steamuxulation-redux.72140/page-4#post-448999,
> this might be relevant for Valve Anti-Cheat 
> used by several popular Steam games.

On a further look, this issue is probably not directly related. steamservice.so calls pread64 libc function, which is supposed to use 64-bit offsets. That doesn't seem to work properly.
Comment 7 Mark Johnston freebsd_committer freebsd_triage 2020-01-08 19:28:34 UTC
(In reply to Alex S from comment #6)
Are you using 32-bit binaries?  I wonder if it is related to the other PR.
Comment 8 Alex S 2020-01-08 19:43:26 UTC
(In reply to Mark Johnston from comment #7)

> Are you using 32-bit binaries?

Yes, the Steam client (the program that produced the backtrace referenced above) is a 32-bit application.
Comment 9 commit-hook freebsd_committer freebsd_triage 2020-01-16 16:00:37 UTC
A commit references this bug:

Author: markj
Date: Thu Jan 16 16:00:28 UTC 2020
New revision: 356794
URL: https://svnweb.freebsd.org/changeset/base/356794

Log:
  MFC r356494:

  PR:	240992

Changes:
_U  stable/12/
  stable/12/sys/compat/linprocfs/linprocfs.c
Comment 10 Mark Johnston freebsd_committer freebsd_triage 2020-01-16 16:01:25 UTC
Thank you for the report.