Send-Document has no job-state check, resurrects canceled jobs and re-prints processing jobs

Đang mở Phù hợp với người mới
#1,833 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 2 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
2/5
Thời gian dự kiến
1-3 giờ
Mức phù hợp với người mới
70/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
c
Lĩnh vực
backend, security

Hướng nghiên cứu

Bắt đầu tại scheduler/ipp.c ở send_document(), nơi việc tìm job và kiểm tra quyền sở hữu được thực hiện trước, sau đó đọc khối xử lý trạng thái quanh dòng 10273-10295 trước lệnh gọi add_file() gần dòng 10224. Tái hiện chuỗi bốn bước trong issue bằng ipptool, dùng máy in raw test trên cổng 8631. Hoàn thành khi một Send-Document gửi tới job đã bị hủy, đã hoàn tất hoặc đã hủy bỏ (aborted) bị từ chối với lỗi và job vẫn ở trạng thái kết thúc, đồng thời hành vi hiện có đối với stopped và held vẫn vượt qua các bài kiểm tra của scheduler.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

Summary

send_document() never checks whether the target job is in a terminal state. A user who owns a job can send a document to a job that has already been canceled, completed, or aborted. CUPS accepts the document, sets the job back to PENDING or HELD, and starts it. A canceled job can therefore be revived with Release-Job; a job that is already being processed can be dragged back to HELD and printed a second time when the hold expires.

Details

scheduler/ipp.c, send_document():

  • The job is looked up (scheduler/ipp.c:10016) and ownership is validated (scheduler/ipp.c:10032).
  • The document is added to the job with add_file() at scheduler/ipp.c:10224, unconditionally.
  • The only state transitions handled are IPP_JOB_STOPPED and IPP_JOB_HELD (scheduler/ipp.c:10273-10295). IPP_JOB_CANCELED, IPP_JOB_ABORTED and IPP_JOB_COMPLETED are not handled; no error is returned.
  • On the last document the function sets start_job = 1 (scheduler/ipp.c:10300) and calls cupsdCheckJobs() (scheduler/ipp.c:10341-10342), which starts the job.
  • On a non-last document it sets job->state = IPP_JOB_HELD, job->hold_until = time(NULL) + MultipleOperationTimeout (scheduler/ipp.c:10310-10312).

The same code is present in CUPS 2.4.20. send_document() needs a check equivalent to if (job->state_value >= IPP_JOB_CANCELED) return IPP_NOT_POSSIBLE; before adding the file.

PoC

Configuration as in the standard cupsd test setup: Listen 127.0.0.1:8631, <Location /> Allow localhost </Location>, one raw printer test.

Sequence and observed wire results:

1. Create-Job (printer-uri=ipp://127.0.0.1:8631/printers/test)
   -> successful-ok, job-id=1, job-state=3 (pending)

2. Send-Document (job-id=1, last-document=true, document=raw bytes)
   -> successful-ok, job-state=5 (processing) then 9 (completed)

3. Cancel-Job (job-id=1)
   -> successful-ok, job-state=7 (canceled)

4. Send-Document (job-id=1, last-document=true, document=raw bytes)
   -> successful-ok

Step 4 is the defect: CUPS accepts a document for a job in state 7 and changes its state. With last-document=false it sets the job to HELD (4); a following Release-Job returns successful-ok and the job returns to PROCESSING (6) and prints again.

Same result when the document is sent while the job is already processing:

1. Print-Job (raw document)
   -> job-state=5 (processing)
2. Send-Document (job-id=1, last-document=false)
   -> successful-ok, job-state=4 (held)
3. Release-Job (job-id=1)
   -> successful-ok, job-state=6 (processing)

Request shape for step 4 (ipptool):

{
  OPERATION Send-Document
  GROUP operation-attributes-tag
  ATTR charset attributes-charset utf-8
  ATTR language attributes-natural-language en
  ATTR uri job-uri ipp://127.0.0.1:8631/jobs/1
  ATTR name requesting-user-name attacker
  ATTR mimeMediaType document-format application/vnd.cups-raw
  ATTR boolean last-document false
  FILE /tmp/poc.txt
}
Ngôn ngữ chính
C
Star
1.8k
Fork
367
Merge trung bình
1 ngày 16 giờ
Pull request đã merge (30 ngày)
7

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của OpenPrinting/cups

Tất cả issue của OpenPrinting/cups

Issue tương tự

Thêm issue về C

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.